swift 4 - HMCharacteristicTypeSerialNumber deprecated

浪子不回头ぞ 提交于 2019-12-10 14:58:30

问题


I want to read information of an accessory, typed HMAccessory, such as Serial number (HMCharacteristicTypeSerialNumber), manufacturer (HMCharacteristicTypeManufacturer), model (HMCharacteristicTypeModel) but they all are deprecated in iOS11, according to this Apple doc here.

I know I can instead use the characteristicType string directly, like below:

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

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

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

But that just makes my code "unconventional", ugly.

Do you know the replacements for the characteristic types of serial number, manufacturer and model? I have searched for hours but still no clues.


回答1:


As you noted, as of iOS 11.0, those characteristicTypeconstants have been deprecated. Access to manufacturer, model, and firmware version info is now obtained through the newer HMAccessory properties manufacturer, model, and firmwareVersion.

For example:

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

However, as far as I can see, while HMCharacteristicTypeSerialNumber has also been deprecated, there isn't any property on HMAccessory to access this info so far.



来源:https://stackoverflow.com/questions/46558500/swift-4-hmcharacteristictypeserialnumber-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!