【发布时间】:2019-09-08 05:32:16
【问题描述】:
自从添加了 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和顶部的icon图片。
@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
看来我需要使用 iOS 12 中添加的func keyImage() -> INImage?。
但我不知道为什么它在 Swift 4.X 中有效,并且找不到任何弃用文档。有人知道这个问题吗?
【问题讨论】:
标签: ios swift sirishortcuts swift5 swift-keypath