2

I am using Apple core bluetooth example .The peripheral is running in foreground in one iphone device.I am running cbcentral client application in one device.It is pairing well when both application in foreground condition.My need is when I run client cbcentral client in background , that delegate methods are not called in which I have mentioned local notification .the notification is not coming in background mode. Can I use NSOperation for running bluetooth delegate methods as we do NSUrlConnection? Will it work in latest iOS version? I checked it, but it is not working.

The code:

-(void) peripheral:(CBPeripheral *)aPeripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error  
 {

          ..............
          ...............
         UILocalNotification *localNotif = [[UILocalNotification alloc] init];

         localNotif.fireDate = [itemDate dateByAddingTimeInterval:-(minutesBefore*60)];

         localNotif.timeZone = [NSTimeZone defaultTimeZone];

         localNotif.alertBody =  @"hi";

         localNotif.alertAction = NSLocalizedString(@"View Details", nil);

         localNotif.soundName = UILocalNotificationDefaultSoundName;


         [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

        ..............
 }

1 Answers1

1

I believe what you are looking for are the core bluetooth UIBackgroundModes here.

Also, you may want to look at Core Bluetooth and backgrounding: Detection of a device and triggering an action, even after being days in background mode? and What exactly can CoreBluetooth applications do whilst in the background?

The core bluetooth background modes work in iOS 5 or later.

Community
  • 1
  • 1
Andrew
  • 15,357
  • 6
  • 66
  • 101
  • Is that code ever called in the background? You must have the bluetooth-peripheral `UIBackgroundMode` enabled for you to be able to get those delegate calls in the background (to my understanding). – Andrew Aug 08 '13 at 13:58
  • Also, you will only have 10 seconds for your app do do stuff whenever it is woken up by the system for a core-bluetooth event. If you need more time, use [beginBackgroundTaskWithExpirationHandler](http://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW28) – Andrew Aug 08 '13 at 14:09