xcode – iOS 7中不推荐使用’isConnected’

xcode – iOS 7中不推荐使用’isConnected’,第1张

概述我知道这是一个愚蠢的问题但是这里有. 我有一个使用isConnected的旧应用程序.现在我收到一个警告,它已被弃用.我可以删除这行代码而不做任何分支,或者我该如何处理.很抱歉这么密集. 这是来自CBPeripheral框架的一些代码. - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForServic 我知道这是一个愚蠢的问题但是这里有.

我有一个使用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 – iOS 7中不推荐使用’isConnected’全部内容,希望文章能够帮你解决xcode – iOS 7中不推荐使用’isConnected’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1033973.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存