ios - CBCentralManager , CBService 委托(delegate)方法将在 iOS6 中以后台模式调用

标签 ios ios6 cbcentralmanager

我正在使用 Apple 核心蓝牙示例。外围设备在一台 iPhone 设备的前台运行。我在一台设备上运行 cbcentral 客户端应用程序。当两个应用程序都处于前台状态时,它配对良好。我的需要是当我运行客户端时cbcentral 客户端在后台,没有调用委托(delegate)方法,我在其中提到了本地通知。通知不会以后台模式出现。 我可以像使用 NSUrlConnection 一样使用 NSOperation 来运行蓝牙委托(delegate)方法吗?它可以在最新的 iOS 版本中运行吗?我检查了它,但它不起作用。

代码:

-(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];

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

最佳答案

我相信您正在寻找的是核心蓝牙 UIBackgroundModes here .

此外,您可能还想看看 Core Bluetooth and backgrounding: Detection of a device and triggering an action, even after being days in background mode? What exactly can CoreBluetooth applications do whilst in the background?

核心蓝牙背景模式适用于 iOS 5 或更高版本。

关于ios - CBCentralManager , CBService 委托(delegate)方法将在 iOS6 中以后台模式调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18029538/

相关文章:

objective-c - 如何在没有 namespace 的 Objective-C 中划分类?

ios - 从iOS上传MP4视频给我一个MOV

ios - 无法运行 iOS UI 自动化的命令行

iphone - 防止在越狱设备上购买假冒应用程序

ios6 - 动态生成通行证

iOS CoreBluetooth - 外围设备连接到范围内的中央设备

swift - 符合 CBCentralManagerDelegate 协议(protocol)

iphone - iOS 6 MFMailComposeViewController : Only support RGBA or the White color space, 这个方法是 hack

ios6 - 如何在我的应用程序 iOS 6 中获取行车路线

ios - CoreBluetooth - didDiscoverPeripheral 从未调用过特定的 serviceUUID,但适用于 nil