我知道这是一个愚蠢的问题,但这里是。
我有一个使用 isConnected 的旧应用程序。现在我收到警告说它已被弃用。我可以删除这行代码而不会产生任何后果,或者我该如何处理。很抱歉这么密集。
这是来自 CBPeripheral 框架的一些代码。
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
// Deal with errors (if any)
if (error) {
NSLog(@"Error discovering characteristics: %@", [error localizedDescription]);
[self cleanup];
return;
}
}
- (void)cleanup
{
// Don't do anything if we're not connected
if (!self.discoveredPeripheral.isConnected) // here is where the warning comes {
return;
}
我想我发现答案应该是
- (void)cleanup
{
// Don't do anything if we're not connected
if (CBPeripheralStateDisconnected) {
return;
}
我还添加了@property(readonly) CBPeripheralState 状态;在我的 .h
我没有收到错误 谁能帮我验证一下?
最佳答案
isConnected
A Boolean value indicating whether the peripheral is currently connected to the central manager. (read-only) (Deprecated in iOS 7.0. Use the state property instead.)
只需将您的代码替换为:
if (self.discoveredPeripheral.state != CBPeripheralStateConnected)
return;
另一方面,如果这就是你在这个方法中的全部,基本上你什么都不做。
所以你可以删除那些死代码。这让我觉得缺少什么......没有清理?
关于xcode - 'isConnected' 在 iOS 7 中被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24437386/