问题
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 characteristicType
constants 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