Core Bluetooth: Cannot find a BLE device in the app again if reinstalling the app without disconnecting the BLE device properly in the app - swift

When I reinstall the app without disconnecting the BLE device, the phone keeps the connection so when I reinstall my app and scan for a BLE device, the last connection will appear in os level, but not in-app level. This causes me to not discover a BLE device if it is not disconnected on the app properly before. My tester insists that if I reinstall the app, I should not see a connection and discover the BLE device anyways.
I can retrieve a BLE device connection in the app if I know the UUID and services, but it is impossible without these as I see in the documentation. Is there any other way to resolve this problem?

This is precisely what retrieveConnectedPeripherals(withServices:) is for. That will return already connected (at the OS level) peripherals that advertise a particular list of services.
You will still need to call connect on the returned peripherals. "Connect" in this context means "to the app," not "to the device." The docs refer to these "app" connections as "local."

Related

cordova-plugin-ble-central autoconnect function always prompting user to pair the device

I'm currently working on an ionic capacitor app that needs to connect automatically with a ble device.
I'm using the ble ionic native plugin:
https://ionicframework.com/docs/native/ble
https://github.com/don/cordova-plugin-ble-central
The goal is sending and receiving bluetooth info and commands to the ble device, which is a car alarm central that controls a few actions like lock and unlock the doors accordingly to the RSSI values on from the device.
So, I'm using the autoconnect function to auto-connect with the device as soon the device is close to range and all works perfectly in Android and iOS. The only issue is that everytime the device reachs the ble range and the ble plugin try connecting, the system prompts the user to accept pairing with the device again.
I need it to work without that pairing prompting everytime. I tried to pairing the device previous to initialize the app but it didn't worked as well. So is it a way to make this autoconnection work without prompting the pairing acceptance everytime it is disconnected?
The issue occurs on Android versions 9 and 10 and iOS.
I've changed my ble hardware interface to ask for a PIN code. I guessed the connection could be considered secure by the OS and prevent prompting the user to pair again. Didn't work as well.
Every connection started by the plugin seems like bounding and connecting as if it was the first time connecting to the device. Even connecting to a known device is prompt the user to input the PIN, which if not provided the OS forgets the device.
Any toughts? Anyone? Thank you!

HttpUrlConnection on Android Wear with connected phone

I am trying to access the network with my Android Wear 2.0 App.
The Problem:
If the smartwatch is connected with the phone then I get an connection timeout. But if the smartwatch isnĀ“t connected with the phone then the connection works fine.
I am using HttpUrlConnection.
Thanks and sorry for my bad english!
This has been answered in a different post:
Android Wear 100% packet loss
The basic idea is that you should not count on having Wi-Fi on the watch. The user may disable Wi-Fi on the watch and then your application will not work on the watch. Instead you should use your companion phone app to connect to the internet. If the phone isn't connected to your watch then use Wi-Fi.
Even if you want your app to run on an LET enabled watch the user may have turned this off or may not have a SIM card installed. At this point the user will most likely still expect your app to work.
So depending on what it is you're working on, if you want your app to work even while connected to the phone, then make a companion app for the phone. If you want your watch app to be a stand-alone app but you still want to be able to access the internet even when the watch is connected to the phone then you're basically saying that you want to drain the user's battery by using Wi-Fi/LTE instead of going via Bluetooth through the phone to access the web.

iOS 7 Bluetooth - app that handles events in background even after phone restart

I want to write a tracking application, which reacts/record when users get in a car and phone automatically pair with Bluetooth hands free. I need also Id of the hands free device.
On Android it is easy, using Broadcast Receiver your app listen to broadcasts that device had been paired with phone. It is working even after phone had been restarted and App did not run after restart.
Is it possible on iOS(7+) ?
You can do it by reading the "Performing Long-Term Actions in the Background" part of this docs
Essentially, using state restoration, the system takes note of what your app was doing when it was killed.
If the app is searching for a bluetooth device and is killed by the system, the system will take care of continuing this research and wake up the app again when the bt device has ben found.
Note that this will work only if the app is killed by the system, not by the user (using the multitask bar). This behavior has changed since iOS 7.
Alternatively, If your BT hardware can be programmed to send advertisements using the ibeacon protocol, your app can be "awakened" by the corelocation/ibeacon api. After that prompt then maybe the corebluetooth pairing code could be initiated.

Share iPhone's internet connection with a non apple device. Tethering

I have a non Apple device used to process some data. It has bluetooth support.
It can be paired with the iPhone via bluetooth.
The device must use iPhone's internet connection to access a remote server.
See the flow:
I pair the device with the iPhone in Settings->Bluetooth.
I use ExternalAccessory framework to send data to the paired device.
The device processes the data and uses iPhone's internet connection to send the data to a remote server.
There is no problem in pairing the device to iPhone ( no jailbreak, by the way ).
Also, the firmware of the device is to be modelled in order to sent https requests via a valid internet connection.
The problem is the tethering, that will allow the iPhone to share it's WIFI or 3G connection with the device.
All I have found so far is tethering the iPhone with a computer, but no word about other non apple devices.
Any idea/link?
Take into account:
The device has bluetooth hardware and can be legally paired with the iPhone, no jailbreak needed.
The data processed by the device MUST avoid the application, and go directly to the remote server: I am not allowed to get the data from the device and use NSURLConnection to pass it to the remote server.
Please suggest a way to share iPhone's internet connection with non apple device.

iphone ios 3.0.1, device is not being able to get a device token nor reporting an error?

ok i have an iphone with ios 3.0.1
i have wifi turned on, no cellular network.
I have created my provisioning profile, my certificate correctly. why?... gonna tell you in a while
anyway, when i run the application, i have put NSLog in
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
but when i run the application i don't get anything, no success nor error.
anyway i tried the SAME APPLICATION and run it on iphone with ios 4.0 and it did work and it printed the device token.
Oh and they are both using the same wifi network.
could it be the device? the ios ? or the security of the wifi connection?
and shouldn't at least give me an error in that case?
could that be caused by the missing library file
warning: Unable to read symbols for "/Library/MobileSubstrate/MobileSubstrate.dylib" (file not found).
thank you
According to Apple Documentation :
No Delegate Callbacks
When the first push-capable app is installed on a device, iOS attempts to
establish a persistent network connection to the push service that
will be shared by all push-capable apps on the device.
If neither delegate callback
application:didRegisterForRemoteNotificationsWithDeviceToken:
nor
application:didFailToRegisterForRemoteNotificationsWithError:
is called, that means that this
connection has not yet been
established.
This is not necessarily an error
condition. The device may not have
Internet connectivity at all because
it is out of range of any cell towers
or Wi-Fi access points, or it may be
in airplane mode. Instead of treating
this as an error, your app should
continue normally, disabling only that
functionality that relies on push
notifications.
Keep in mind that network availability
can change frequently. Once the
persistent connection to the push
service succeeds, one of the
previously-mentioned application
delegate methods will be called.
Push notifications use the cellular
data network whenever possible, even
if the device is currently using Wi-Fi
for other network activity such as web
browsing or email. However, the push
service will fall back to Wi-Fi if
cellular data service isn't available.
If your device is capable of using the
cellular data network, check that it
has an active cellular data plan. Turn
off Wi-Fi in Settings and see if you
can still browse the web with Safari,
for example. On the other hand, if the
push service is using Wi-Fi, any
firewalls between your device and the
Internet must allow TCP traffic to and
from port 5223.
NOTE: There is a separate persistent
connection to the push service for
each environment. iOS establishes a
persistent connection to the sandbox
environment for development builds; ad
hoc and distribution builds connect to
the production environment.
About second part of your question, MobileSubstrate is not the culprit, this is a normal log message... from a jailbroken iPhone :)