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

2

5

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+) ?

Inherent answered 9/5, 2014 at 14:13 Comment(5)
You can't launch an app, in non-jailbroken devices, by code. So no "programmatically" launch at boot. With Bluetooth device, if the device has bluetooth enabled and already paired, you may trigger a pop-up, asking for using your app. Allow/Deny AlertView, and you may encourage the user to launch your app (and do a few things on background).Officiary
I don't really want to be launched at boot. I want to be notified when bluetooth device connects, even when my app is not running. This is how it works on Android.Inherent
That's not how it works on iOS. If your app is not running, you won't get anything.Officiary
This is a desired feature but not possible today. Maybe iOS8 will bring this improvement. Until then, only iBeacons can be used to wake your app.Petronel
"Performing Long-Term Actions in the Background" in CoreBluetooth may help you. You can make your car and phone as Central and Peripheral. developer.apple.com/library/ios/documentation/…Delinquent
F
3

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.

Freberg answered 19/5, 2014 at 17:47 Comment(1)
Are you sure that this survives a phone reboot? My testing so far (iOS 7.1) suggests that neither scanning or advertising is resumed after a device restart. They do continue and the app is resumed (briefly) if memory pressure caused the app to close.Novara
S
1

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.

Siffre answered 20/5, 2014 at 4:18 Comment(1)
BT HW can not be programmed :(Inherent

© 2022 - 2024 — McMap. All rights reserved.