I'm building a bluetooth device that is connected to my app. The device I'm building will be connected to the phone as much as possible, and when the user leaves the device's range and then comes back later, I expect the OS to wake the app up when it reconnects in the background using the CoreBluetooth willRestoreState wake up method. Using just CoreBluetooth for pairing, I've confirmed that the phone will reconnect to the device while in the background and the app gets woken up when that happens.
I'm hoping to use ASK for pairing instead as it's a much nicer user experience. When I initiate and confirm pairing via ASK, I can see that it's connected and paired successfully and I see my device and app connected as I expect. But when the device goes away, and the app has been in the background, and then I come in range of the phone, the device never reconnects automatically in Bluetooth settings. When I manually tap the device in settings to connect, it does connect, but I don't think my app gets woken up and restored as I don't see the requests I expect happening when it's in the background.
Does ASK support scanning for peripherals via CoreBluetooth while in the background, or automatic reconnection? I assumed that when my app is launched, I activate the ASAccessorySession session, and the .activated callback will fire, but I'm not seeing that happen.
I'm hoping to use ASK for pairing instead as it's a much nicer user experience. When I initiate and confirm pairing via ASK, I can see that it's connected and paired successfully and I see my device and app connected as I expect.
You're actually moving in the right direction here but you've misunderstood the relationship between ASK and CoreBluetooth. ASK's role here is to establish the relationship between a particular accessory and your app. However, once that relationship is established, CoreBluetooth's background operation should work exactly the same it does without ASK.
That's also why the answer here:
Does ASK support scanning for peripherals via CoreBluetooth while in the background, or automatic reconnection?
...is no. The point of ASK is to get the users approval of the relationship between your app and accessory. By defintion, that has to happen in the foreground.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware