swift 4 - HMCharacteristicTypeSerialNumber 弃用

标签 swift deprecated ios11 swift4 homekit

我想读取一个配件的信息,类型为HMAccessory,例如序列号(HMCharacteristicTypeSerialNumber)、制造商(HMCharacteristicTypeManufacturer)、型号(HMCharacteristicTypeModel) 但根据此 Apple 文档 here,它们在 iOS11 中均已弃用.

我知道我可以直接使用 characteristicType 字符串,如下所示:

HMCharacteristicTypeSerialNumber -> 00000030-0000-1000-8000-0026BB765291

HMCharacteristicTypeManufacturer -> 00000020-0000-1000-8000-0026BB765291

HMCharacteristicTypeModel-> 00000021-0000-1000-8000-0026BB765291

但这只会让我的代码变得“非常规”、丑陋。

序列号、厂商、型号等特征类型的替换你知道吗?我已经搜索了几个小时,但仍然没有任何线索。

最佳答案

如您所述,从 iOS 11.0 开始,那些 characteristicType 常量已被弃用。现在可以通过较新的 HMAccessory 属性 manufacturermodelfirmwareVersion.

例如:

print("Manufacturer: \(accessory.manufacturer)")
print("Model: \(accessory.model)")
print("Firmware Version: \(accessory.firmwareVersion)")

但是,据我所知,虽然 HMCharacteristicTypeSerialNumber 也已被弃用,但目前 HMAccessory 上没有任何属性可以访问此信息。

关于swift 4 - HMCharacteristicTypeSerialNumber 弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46558500/

相关文章:

快速 TableView 将 reloadData 更改为 insertRows

Swift:结果的失败类型不能是协议(protocol) - "Type ' 任何 ShadowError' 无法符合错误”

ios - 用其他自定义值替换零值

java - 持久通知的前台服务

android - 在 google maps API v2 for android 中使用或不使用 getMyLocation ()?

ios - 此 iPhone 5s 运行的是 iOS 11.0.3,此版本的 Xcode 可能不支持

ios - 如何在 NSObject 类 : Swift 中添加动态行为

swift - 'init(源 :)' was deprecated in OS X 10. 14:核心图像内核语言 API 已弃用

objective-c - 我发现 tableview 无法在 iOS 11 中滚动

ios - Afnetworking multipart/formdata 返回请求在 ios 11 中失败,但在 ios 10 中工作正常