自从添加了 Siri 快捷方式后,我就使用INIntent
了对象。为此,我做了一个意图定义,它INIntent
自动生成了一个对象。
@available(iOS 12.0, watchOS 5.0, *)
@objc(SpotConditionIntent)
public class SpotConditionIntent: INIntent {
@NSManaged public var spotId: String?
@NSManaged public var spotName: String?
}
为了自定义 Siri 快捷语音记录屏幕,我添加了一个便利初始化程序。基本上是添加suggestedInvocationPhrase
顶部图标图像。
@available(iOS 12, *)
extension SpotConditionIntent {
convenience init(spotId: String, spotName: String) {
self.init()
self.spotId = spotId
self.spotName = spotName
self.suggestedInvocationPhrase = "\(NSLocalizedString("how_are_waves_text", comment: "How are the waves at")) \(spotName)?"
if let uiimage = UIImage(named: "check-surf-icon"), let data = uiimage.pngData() {
let inImage = INImage(imageData: data)
setImage(inImage, forParameterNamed: \.spotName)
}
}
}
今天,我尝试将整个项目转换为 Swift 5,并且构建没有问题。(代码中没有实际的变化。)但是它在运行时崩溃并带有非常奇怪的消息。
线程 1:致命错误:无法解开关键路径类型
XXXX9SpotConditionIntentCXD
它指出了setImage(inImage, forParameterNamed: \.spotName)
.
我刚刚发现setImage(,forParameterNamed)
文档中不存在。
https://developer.apple.com/documentation/sirikit/inintent
好像我需要使用func keyImage() -> INImage?
iOS 12 中添加的。
但我不知道为什么它在 Swift 4.X 中有效,并且找不到任何弃用文档。有人知道这个问题吗?