Core Bluetooth advertise and scan in the background

前端 未结 3 1457
梦谈多话
梦谈多话 2020-11-30 20:21

I have been trying to setup an app to make the device both scan for peripherals and advertise as a peripheral. The goal is for two devices to be woken up in the background w

3条回答
  •  我在风中等你
    2020-11-30 21:04

    You should elaborate on how you're testing this, because theoretically it looks like it should work. There's two primary issues you may be facing:

    1.) Scanning is throttled down when iOS devices are in the background.

    • While scanning in the foreground will likely immediately discover a device advertising next to it, discovery in the background can take up to ~60 times longer. The iOS system makes no assumptions that the user would prefer one app to have better Bluetooth functionality than another (or that only one app wants to use it). And since it is shared functionality, they want users to have a uniform experience across apps. You should check out the technical specifications regarding Advertising and Scanning intervals to get a better idea of what Apple has to do under the covers.

    2.) Your devices may have already discovered each other before entering the background.

    • We must remember that Apple disables the CBCentralManagerScanOptionAllowDuplicatesKey scanning flag when we enter the background. Since you're not even specifying this flag, it defaults to NO anyways. So if they've even seen each other once, you will not get another callback when they are in the background.

提交回复
热议问题