0
votes

Our beacon hardware was programmed to be iBeacon + writeable BLE . So i can discover it with iBeacon , and also connect to it via BLE.

I would like to scan for iBeacon, and when i enter the region (app is in background) , and the delegate is being called, he will than switch to BLE and connect to the device with BLE :

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    // here connect as usual via bluetooth
}

So,as i said, i can separately write/discover the hardware, but when i am trying to connect to the module, from the delegate via BLE ( when app in background,i enter the region,delegate is ON, than in background trying to connect with BLE, its not working, although i can in background do other things when inside a region, for example, connect to a server .)

Is there anything i can do to make it happen? i was also trying to stop the beacon region monitoring, but even so, he can't connect to the BLE from background .

1
do you have the background mode key set in the info.plistDaij-Djan
yes,all of them. seems like the problem is that the app awakes for 10 seconds only and the BLE does not have enough time to connect.. can you get more time from the system ?Curnelious

1 Answers

1
votes

to do stuff in bg you need to request time from the os. you then get an identifier.

//identifier
@property(nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskIdentifier;

request it by calling:

if(!self.backgroundTaskIdentifier) {
    self.backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        NSLog(@"expired, fail, throw!!!");
        @throw [NSException exceptionWithName:@"BeaconServiceKilled" reason:@"Expired in bg" userInfo:nil];
    }];
}

when done then release it

if(self.backgroundTaskIdentifier) {
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskIdentifier];
    self.backgroundTaskIdentifier = 0;
}