xcode CoreBluetooth[WARNING] 没有恢复标识符但委托实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20956880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:31:02  来源:igfitidea点击:

CoreBluetooth[WARNING] has no restore identifier but the delegate implements

xcodebluetooth

提问by Beno?t Freslon

I'm using the CoreBluetooth but I got this warning message in the output.

我正在使用 CoreBluetooth,但在输出中收到此警告消息。

CoreBluetooth[WARNING] has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported!

CoreBluetooth[WARNING] 没有恢复标识符,但委托实现了 centralManager:willRestoreState: 方法。不支持恢复!

I'm using this code:

我正在使用此代码:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerOptionShowPowerAlertKey, nil];

myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];

I don't know what's wrong.

我不知道怎么了。

Thanks.

谢谢。

回答by foggzilla

This is in regards to CoreBluetooth's save/restore optional feature, see "Opt In to State Preservation and Restoration" part of the documentationfor more details.

这是关于 CoreBluetooth 的保存/恢复可选功能,请参阅文档的“选择加入状态保存和恢复”部分了解更多详细信息。

What looks to be happening is that you are implementing the right delegate method to use this feature but you are not providing a restoration identifier in your call to initialize the CBCentralManager.

看起来正在发生的事情是您正在实施正确的委托方法来使用此功能,但您没有在调用中提供恢复标识符来初始化CBCentralManager.

There are two options to resolve the warning:

有两个选项可以解决警告:

  1. If you want to use this feature you should provide a string identifier that represents the central or peripheral manager to CBCentralManager like so:

    myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil
         options:@{ CBCentralManagerOptionRestoreIdentifierKey:
         @"myCentralManagerIdentifier" }];
    
  2. If you don't want to use this feature then remove the centralManager:willRestoreState:method from your delegate.

  1. 如果您想使用此功能,您应该向 CBCentralManager 提供一个代表中央或外围管理器的字符串标识符,如下所示:

    myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil
         options:@{ CBCentralManagerOptionRestoreIdentifierKey:
         @"myCentralManagerIdentifier" }];
    
  2. 如果您不想使用此功能centralManager:willRestoreState:,请从您的委托中删除该方法。

Doing either one should resolve your warning.

做任何一个都可以解决您的警告。