CoreBluetooth advertising in the background on iOS 10

Firstly: I have an iPad Air 2 and iPhone 7. For further reading, we evaluate that the application is active and open on the iPad and in the background on the iPhone. The application is exactly the same, even with the same Bluetooth service UUIDs and the same DataLocalNameKey.

I want to write an application that can advertise a bluetooth service in the background and can open this service (optimally and in the background). As I already read , I can’t use the beacon technology of apples, because there you can get only scanning / notification with beacons in the background (I tested this, it works fine) but not for advertising. So I started using CoreBluetooth, as described in the SO mentioned above, because there you can advertise in the background.

My application calls the didDiscoverPeripheral method in CBCentralManagerDelegate on the iPhone (the application is in the background), so it detected the iPad. The property isAdvertising CBPeripheralManager on the iPhone is true . But didDiscoverPeripheral not called an iPad. I am a bit confused. One option is that my iPad can no longer detect the iPhone for some reason, or my iPhone is lying and it is not being advertised.

So I thought I was just a little stupid and was looking for “CoreBluetooth debugging apps”. I found Vicinity and AltBeacon . And with both applications the behavior is the same! If you use the background (press the "home / sleep" button) of the advertising application, the viewing application will no longer be able to detect it. If you open a background application, it will instantly open it. Both applications mention that they can be broadcast in the background.

I am doing something wrong; is this behavior expected? I misunderstood the framework? Can you confirm this behavior?

To confirm this, the fastest way is to install Vicinity on two devices (you must add the NSBluetoothPeripheralUsageDescription key in Info.plist), install one device for broadcasting and press the home button.

+4
source share
2 answers

it was a bug in ios 10.0 (1) and partially fixed in ios 10.1

src: https://forums.developer.apple.com/thread/51309

+2
source

This is not something special for iOS 10 - it has always been on iOS. On iOS, apps simply cannot send standard Bluetooth LE advertisements when they are in the background . They must be in the foreground to do this.

However, limited iOS support for apps promoting GATT services in the background. This uses a proprietary method that only works with other iOS devices that are looking for these services. (Since it uses a non-standard proprietary scheme, the same method will not work, for example, for advertising beacons.)

Here's how Apple describes it:

... you should know that advertising when your application is in the background works differently than when your application is in the foreground. In particular, when your application advertises in the background:

  • The CBAdvertisementDataLocalNameKey advertising key is ignored, and the local peripheral name is not advertised.
  • All service UUIDs contained in the CBAdvertiseDataServiceUUIDsKey advertising key value are placed in a special "overflow" area; they can only be detected by an iOS device that explicitly scans them.
  • If all of the applications that are advertising are in the background, the frequency with which your peripheral device sends proposal packages may decrease.

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

+4
source

Source: https://habr.com/ru/post/1269044/


All Articles