sirishortcuts - “发生未知错误”尝试启动我的 Siri 快捷方式时
问题描述
我正在将 siri 快捷方式添加到我现有的应用程序中。共有三种快捷方式,一种以特定值启动应用程序,一种用于将值增加一个量,另一种用于将值减少一个量。快捷方式代码,用于启动应用程序附在此处:
//
// StartMeetingIntentHandler.swift
//
import Intents
import SwiftUI
class StartMeetingIntentHandler: NSObject, StartMeetingIntentHandling {
@ObservedObject var meeting = Meeting()
func handle(intent: StartMeetingIntent, completion: @escaping (StartMeetingIntentResponse) -> Void) {
if let attendees = intent.attendees {
meeting.meetingStarted()
meeting.addAttendee(numberToAdd: Int(truncating: attendees))
completion(StartMeetingIntentResponse.success(result: attendees))
} else {
print("failure")
}
}
func resolveAttendees(for intent: StartMeetingIntent, with completion: @escaping (StartMeetingAttendeesResolutionResult) -> Void) {
let people = Int(truncating: intent.attendees ?? 0)
if people < 0 {
completion(StartMeetingAttendeesResolutionResult.unsupported(forReason: StartMeetingAttendeesUnsupportedReason.negativeNumbersNotSupported))
} else if people > 1000 {
completion(StartMeetingAttendeesResolutionResult.unsupported(forReason: StartMeetingAttendeesUnsupportedReason.greaterThanMaximumValue))
} else {
completion(StartMeetingAttendeesResolutionResult.success(with: people))
}
}
}
当我从快捷方式应用程序运行快捷方式时,我收到消息“发生未知错误”。如何进行调试?
在查看了模拟器的控制台后,我发现了两个错误:1)
[INCExtensionRequest _extensionContextHost] Unexpected extension context class (null)
和 2)
-[WFAction runWithInput:userInterface:parameterInputProvider:variableSource:completionHandler:]_block_invoke Action <WFHandleCustomIntentAction: 0x7ffe845b1a10, identifier: com.theapapp.wastedtime.AddAttendeeIntent, parameters: 2> finished with error {domain: WFIntentExecutorErrorDomain, code: 103}. Error Domain=WFIntentExecutorErrorDomain Code=103 "An unknown error occurred." UserInfo={NSLocalizedDescription=An unknown error occurred., WFIntentExecutorIntentResponseErrorKey=<INIntentResponse: 0x600003f63f80> {
userActivity = <null>;
code = INIntentResponseCodeFailure;
}, WFIntentExecutorIntentErrorKey=<INIntent: 0x6000018f0630> {
people = 1;
}, NSLocalizedFailureReason=Could Not Run Add Attendee}
解决方案
我有这个完全相同的错误,因为我不小心在 IntentHandler.swift 文件中返回了我的 CustomIntent 而不是我的 CustomIntentHandler
前:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
if intent is CustomIntent {
return CustomIntent()
}
return self
}
}
后:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
if intent is CustomIntent {
return CustomIntentHandler()
}
return self
}
}
推荐阅读
- java - 如何在 UML 中表示双向关联?
- c - 在现代系统上编译旧版本的 gcc
- c# - RavenDB PeriodicExport 错误“RequestEntityTooLarge”
- c++ - BOOST C++ 获取线串的旋转或方向
- php - 使用 Mike42/Escpos-php 库将 PDF 文件打印到网络 POS 打印机
- typescript - 有没有办法使用带有可选键的打字稿界面,然后具体化键在那里?
- android - 安卓后台线程控制涂鸦蓝牙设备
- reactjs - 重新加载它重定向到电子反应中的组件js文件,但从侧边栏它工作正常
- c# - 明确定义时无法捕获 NullReferenceException
- react-native - 在三个屏幕之间导航