我正在使用 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/