3

自从添加了 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 中有效,并且找不到任何弃用文档。有人知道这个问题吗?

4

1 回答 1

2

据我检查...

这两种方法在 Objective-C 中可用。

- imageForParameterNamed:

- setImage:forParameterNamed:

这些方法生成的接口显示为...

// Set an image associated with a parameter on the receiver. This image will be used in display of the receiver throughout the system.
@available(iOS 12.0, *)
open func __setImage(_ image: INImage?, forParameterNamed parameterName: String)

@available(iOS 12.0, *)
open func __image(forParameterNamed parameterName: String) -> INImage?

Xcode 的文档或代码建议不会向您显示这些,但您可以在 Swift 5 代码中使用它们:

    intent.__setImage(image, forParameterNamed: "spotName")

但是,在将您的应用程序提交到 App Store 时,使用下划线引导的方法可能会被视为使用私有 API。

当 Apple 正在对某些方法进行swiftifying并且尚未完成时,有时会发生这种事情。

至于现在,你能做的就是……

  • 立即向 Apple 发送错误报告

  • 为这些方法编写一个 Objective-C 包装器并将其导入 Swift

或者

  • 延迟提交直到将提供修复此问题的新 SDK(可能是几年...)
于 2019-04-17T22:47:01.990 回答