xcode - 'isConnected' 在 iOS 7 中被弃用

标签 xcode ios7 deprecated

我知道这是一个愚蠢的问题,但这里是。

我有一个使用 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

我没有收到错误 谁能帮我验证一下?

最佳答案

Apple Documentation说:

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/

相关文章:

ios - 将 tableView 连接到 .XIB 中的数据源

ios - Swift:不小心将一个导出添加到两个不同的文件,删除了两个导出

ios - 报告 ALAssetRepresentation 元数据方法崩溃

c# - 如何在当前代码中限制给定方法/类的使用

android - Android 上弃用的类

objective-c - 是否存在像 ipad 中那样显示周 View 的库?

xcode - 如何摆脱 'Failed to get task for pid"错误?

ios - 如何复制和重命名/重构 ios xcode 示例项目作为我的起点?

ios - ios 7 中 tableview 中的单元格数量错误

git - 我如何将 git 分支标记为已弃用