0

I have an iOS app that connects to a bluetooth peripheral (think of it as a connected button). The peripheral is in a fixed location so isn't always within range of the iOS device. My app is meant to run as a background task and the peripheral periodically notifies my app of button presses.

I find that iOS sometimes kills my app due to (I believe) memory pressure. I thought that BLE state preservation and restoration would help me:

https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html

...by relaunching a killed app whenever the bluetooth connection to the peripheral was restored and a button on the peripheral was pressed. However, this post:

BLE background reconnect

...(the comment by Anton) seems to suggest that state restoration is a bit flaky and can't restore state after BT is turned off/on or after airplane mode etc.

Is this still the case with BLE state restoration. Am I wasting my time trying to get it to work? If it does work, are there any good example implementations anywhere?

If I can't use state restoration, are there any other options?

  • keep my app footprint small so it's less likely to be killed by iOS?
  • add some kind of keep-alive comms to a remote server that keeps the app alive?
  • add functionality such as messaging or VOIP to my app (I know it would need to be legitimate to get through an app store approval). Would that allow the app to be relaunched and a connection reestablished to by BLE peripheral, or does the wakeup only allow VOIP specific API calls?
  • Anything else?

Clearly the list above as less preferred to getting BLE state restoration to do the work for me. Any advise greatly appreciated.

Martin Harrison
  • 145
  • 2
  • 11
  • Where do you see any comments about not reconnecting after toggling airplane mode? I also am fairly certain that you'll get restarted after reboot now if you had a long-running connection. Have you actually tried to implement state restoration and had problems? I have found BLE difficult to use well on iOS, but I wouldn't start by trying to work around it before you've encountered any problems. (Of course if your memory usage is high, you should work on that, but that's completely separate.) – Rob Napier Apr 11 '17 at 20:30
  • I believe I've seen the airplane mode issue mentioned in a number of places by developers including here: [link](https://forums.developer.apple.com/thread/26798) (which is the same poster as my link in my original post) and what's not clear to me is whether these issues still persist or are related to older versions of iOS. I'm trying to get state restoration working but saw some negative posts which made me want to check I wasn't wasting my time! Any links to a good working solution would be great! – Martin Harrison Apr 11 '17 at 21:25
  • Can anyone suggest any techniques? – Martin Harrison Apr 13 '17 at 09:30
  • Are you encountering actual problems? Or is this a generic "will I ever have problems" question. The later is off-topic here. The only way to do what you want to do is with state restoration. No one can promise that there will be no iOS bugs around that, or that Apple won't break it. But you can't do what you're trying to do without state restoration, so start there (or end the project if you don't believe it's going to work) – Rob Napier Apr 13 '17 at 13:25

1 Answers1

2

I wrote a comment here a while back that you might want to read as well: Does CBCentralManager connect ever time out?

Anyhow, keeping your app footprint small might make it less likely that your app will be killed early on, but eventually it will happen regardless. VOIP could be a good solution if you really do have a legitimate reason to use it. You might want to read up on VOIP push messages. Subscribing to significant location changes can also be very helpful, but only for users that move around a lot. If you have users that use BLE with “stationary” iPads for example it won’t help. As I have mentioned before, you can get it to work sort of “ok” (depending on your use-case), but 100% is impossible. Also, the Apple Watch bug thing is a bit unfortunate. Since I now have a watch paired I have basically given up on Core Bluetooth for my own use.

I have been in contact with some Apple bluetooth engineers a while back and they more or less confirmed that they are aware of the issues. Why they won’t fix it I don’t know, but it is clear that it is not a hight priority for them to make sure that third party peripherals works well. Of corse when it comes to their own products (Watches, EarPods etc..) they don’t have the same limitations.

Anton
  • 978
  • 8
  • 16