CoreBluetooth状态保存问题:在iOS 7.1中未调用willRestoreState
大家好.过去几周我一直致力于蓝牙LE项目,并遇到了障碍.我无法在iOS 7/7.1中正常恢复状态.我遵循了(我认为)Apple提出的所有步骤,并在其他堆栈溢出帖子上获得了一些线索.
我的测试用例:
结果iOS 7:
应用程序将在AppDelegate didFinishLaunchingWithOptions函数中响应,但是launchOptions [UIApplicationLaunchOptionsBluetoothCentralsKey]内部的NSArray内容始终是一个空数组.
iOS 7.1上的结果:
进展!我可以在100%的时间内在UIApplicationLaunchOptionsBluetoothCentralsKey数组中看到我的CentralManager密钥,但永远不会调用fromRestoreState.
码:
//All of this is in AppDelegate for testing
@import CoreBluetooth;
@interface AppDelegate () <CBCentralManagerDelegate, CBPeripheralDelegate>
@property (readwrite, nonatomic, strong) CBCentralManager *centralManager;
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{CBCentralManagerOptionRestoreIdentifierKey:@“myCentralManager”}];
//Used to debug CM restore only
NSArray *centralManagerIdentifiers = launchOptions[UIApplicationLaunchOptionsBluetoothCentralsKey];
NSString *str = [NSString stringWithFormat: @"%@ %lu", @"Manager Restores: ", (unsigned long)centralManagerIdentifiers.count];
[self sendNotification:str]; …Run Code Online (Sandbox Code Playgroud)