【问题标题】:will CBCentralManager ,CBService delegate methods be called in background mode in iOS6CBCentralManager , CBService 委托方法会在 iOS6 的后台模式下被调用吗
【发布时间】:2013-08-04 11:17:32
【问题描述】:

我正在使用 Apple 核心蓝牙示例。外围设备在一台 iphone 设备的前台运行。我在一台设备上运行 cbcentral 客户端应用程序。当两个应用程序都处于前台条件时配对良好。我需要的是当我运行客户端时cbcentral 客户端在后台,没有调用我提到的本地通知的委托方法。通知不是以后台模式出现的。 我可以像使用 NSUrlConnection 一样使用 NSOperation 来运行蓝牙委托方法吗?它可以在最新的 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];

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

【问题讨论】:

    标签: ios ios6 cbcentralmanager


    【解决方案1】:

    我相信您正在寻找的是核心蓝牙UIBackgroundModeshere

    另外,你可能想看看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 或更高版本。

    【讨论】:

    • 是否曾在后台调用过该代码?您必须启用蓝牙外围设备UIBackgroundMode 才能在后台接听这些委托呼叫(据我所知)。
    • 此外,每当系统为核心蓝牙事件唤醒您的应用程序时,您只有 10 秒的时间来执行操作。如果您需要更多时间,请使用beginBackgroundTaskWithExpirationHandler
    猜你喜欢
    • 1970-01-01
    • 2016-05-12
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多