swift 4 - HMCharacteristicTypeSerialNumber depreca

2019-06-25 03:54发布

问题:

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.