【问题标题】:swift 4 - HMCharacteristicTypeSerialNumber deprecatedswift 4 - 不推荐使用 HMCharacteristicTypeSerialNumber
【发布时间】:2018-03-15 11:19:18
【问题描述】:

我想读取一个配件的信息,输入HMAccessory,例如序列号(HMCharacteristicTypeSerialNumber),制造商(HMCharacteristicTypeManufacturer),型号(HMCharacteristicTypeModel),但它们都在iOS11中被弃用,根据这个苹果文档here

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

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

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

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

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

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

【问题讨论】:

  • 我对这些被弃用的假设不仅是 Characteristic -> UUID 映射将在未来消失,而且要求这些 UUID 将不再返回有效结果。很遗憾,我还没有任何答案。

标签: swift deprecated ios11 swift4 homekit


【解决方案1】:

如您所述,从 iOS 11.0 开始,那些 characteristicTypeconstants 已被弃用。现在可以通过较新的HMAccessory 属性manufacturermodelfirmwareVersion 访问制造商、型号和固件版本信息。

例如:

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

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

【讨论】:

  • 任何可用的 Apple 文档或链接说明为什么没有添加任何属性来访问“HMCharacteristicTypeSerialNumber”?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-18
  • 1970-01-01
  • 2019-08-18
  • 2017-03-26
  • 2023-03-04
  • 2012-06-06
  • 1970-01-01
相关资源
最近更新 更多