0
votes

My iOS app is communicating with a BTLE device through a proprietary SDK (i.e. non core bluetooth framework). The pairing also takes place through this SDK (PnP code). The SDK services has many non-standard Bluetooth services & characteristics.

As soon as the user switches to another app, i.e the main app is running in the background, I can't access the SDK services anymore. However, it is vital that I keep receiving data from the device, even when my app is running in the background.

As per my research, Apple only allows few Background Modes, listed here https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html (Search the page for "UIBackgroundModes"), e.g. audio, location,voip,fetch,remote-notification,newsstand-content,external-accessory,bluetooth-central,bluetooth-peripheral

As the SDK is using its own bluetooth framework and many non-standard Bluetooth Services, what option, if any, do I have to allow my app to keep hitting the services at continuous intervals even when the app is running in the background?

I was thinking about using a location service in background. there I have a doubt:

  1. If Apple sees that Location service has little or no use within my app then they may reject it?

  2. If my iPhone is on plan surface then Its not going to call didUpdateLocation method & in this case I am not able to communicate with SDK?

Please suggest, what is the best way to run my application in background so that I will not face any problem.

2
Are you sure that your SDK isn't using Core Bluetooth "under the covers"? There is no other way an SDK can access the BTLE hardware and still allow your app to be approved for the app storePaulw11

2 Answers

1
votes

In XCode, go to your project->Capabilities->Background Modes and mark the Background Modes to On. Mark also Uses Bluetooth LE accessories:

enter image description here

1
votes

If your application is only for Adhoc use, then you can play an audio in background and keep application live (this will cause rejection too)

Please note, that Apple approves BTLE applications if they use CoreBluetooth framework. (https://developer.apple.com/library/ios/qa/qa1657/_index.html)

If your are searching an easy way for switching to Apple's CoreBluetooth, LGBluetooth is an awesome lightweight solution, You can go and checkout https://github.com/l0gg3r/LGBluetooth Framework works over CoreBluetooth, and ideally works in background.

Here are awesome examples of using LGBluetooth (note: even connection is handled by framework)

read operation

    [LGUtils readDataFromCharactUUID:@"f045"
                             serviceUUID:@"5ec0"
                              peripheral:peripheral
                              completion:^(NSData *data, NSError *error) {
                                  NSLog(@"Data : %s Error : %@", (char *)[data bytes], error);
                              }];

write operation

        int8_t dataToWrite = 0xFF;
        [LGUtils writeData:[NSData dataWithBytes:&dataToWrite length:sizeof(dataToWrite)]
               charactUUID:@"cef9"
               serviceUUID:@"5ec0"
                peripheral:peripheral completion:^(NSError *error) {
                    NSLog(@"Error : %@", error);
                }];