Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios INIntent`setImage`使Swift 5中的运行时崩溃_Ios_Swift_Sirishortcuts_Swift5_Swift Keypath - Fatal编程技术网

Ios INIntent`setImage`使Swift 5中的运行时崩溃

Ios INIntent`setImage`使Swift 5中的运行时崩溃,ios,swift,sirishortcuts,swift5,swift-keypath,Ios,Swift,Sirishortcuts,Swift5,Swift Keypath,自从添加了Siri快捷方式后,我就使用了InContent对象。为此,我做了一个intent定义,它自动生成了一个INIntent对象 @available(iOS 12.0, watchOS 5.0, *) @objc(SpotConditionIntent) public class SpotConditionIntent: INIntent { @NSManaged public var spotId: String? @NSManaged public var spot

自从添加了Siri快捷方式后,我就使用了
InContent
对象。为此,我做了一个intent定义,它自动生成了一个
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快捷语音记录屏幕,我添加了一个方便的初始值设定项。基本上是添加
建议的短语和顶部图标图像

@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(在图像中,参数名称:\.spotName)

我刚刚发现
setImage(,forParameterNamed)
在文档中不存在

似乎我需要使用iOS 12中添加的
func keyImage()->INImage?

但我不知道为什么它能在Swift 4.X中工作,也找不到任何有关弃用的文档。有人知道这个问题吗?

据我所知

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

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

// 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")
不过,在向应用商店提交应用程序时,使用下划线引导的方法可能被视为使用私有API

这类事情有时发生在苹果正在快速改进某些方法但尚未完成时

至于现在,你能做的是

  • 立即向苹果发送错误报告

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

  • 延迟提交,直到提供解决此问题的新SDK (可能是几年…)
据我所知

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

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

// 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")
不过,在向应用商店提交应用程序时,使用下划线引导的方法可能被视为使用私有API

这类事情有时发生在苹果正在快速改进某些方法但尚未完成时

至于现在,你能做的是

  • 立即向苹果发送错误报告

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

  • 延迟提交,直到提供解决此问题的新SDK (可能是几年…)

非常有趣。在iOS12测试版的某个版本中,它是setImage,但苹果在黄金版本中将它改为setImage。它非常有趣。在iOS12测试版的某个版本中,它是_usetimage,但苹果在黄金版本中将它改为setImage。