2016-10-05 221 views
0

距离Ios SDK 10.0,类CBCentralManager现在从CBManagerCoreBluetooth兼容性问题

CBManager继承在IOS被引入10.0,它在早期版本中不可用。

state属性现在枚举为CBManagerState

CBManagerState也在iOS的10.0介绍,它是不是在早期版本。

这意味着CBCentralManagerstate属性是CBManagerState型,所以当你阅读的状态,你会得到一个CBManagerState这是只有在iOS 10.0

提供。但对于较早的iOS版本,该类型不可用,因此您必须将其转换为以前识别的(不推荐在iOS 10.0中使用)CBCentralManagerState枚举类型。

CBCentralManagerState(rawValue: centralManager.state.rawValue) ?? .Unknown 

现在你可以使用这个state属性进入较早的IOS版本。当您的应用程序准备好iOS 10.0或更高版本时,只有您可以直接使用它作为CBManagerState

+0

http://stackoverflow.com/questions/39577272/how-to- convert-value-of-type-cbmanagerstate-to-expected-type-cbcentralmanager? – Larme

回答

0

'CBManagerState'仅适用于iOS 10.0或更新版本。

用CBManagerState替换您的所有CBCentralManagerState和CBPeripheralManagerState枚举。 枚举是二进制兼容的,所以你的代码可以在任何iOS版本上正常运行。 如果你想仍然能够用Xcode 7编译你的代码,你可以添加一些非常简单的定义。

#if __IPHONE_OS_VERSION_MAX_ALLOWED <= __IPHONE_9_3 
#define CBManagerState CBCentralManagerState 
#define CBManagerStateUnknown CBCentralManagerStateUnknown 
#define CBManagerStateResetting CBCentralManagerStateResetting 
#define CBManagerStateUnsupported CBCentralManagerStateUnsupported 
#define CBManagerStateUnauthorized CBCentralManagerStateUnauthorized 
#define CBManagerStatePoweredOff CBCentralManagerStatePoweredOff 
#define CBManagerStatePoweredOn CBCentralManagerStatePoweredOn 
#endif 

,如果你想了解更多关于此变更,请按以下链接:

Best practice for checking if an enum exists in iOS version?

CBCentralManagerState deprecated iOS 10