【问题标题】:"An Unknown error occurred" When trying to launch my Siri Shortcut“发生未知错误”尝试启动我的 Siri 快捷方式时
【发布时间】:2020-10-04 06:51:49
【问题描述】:

我正在向我现有的应用程序添加 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}

【问题讨论】:

  • 我已在控制台中检查并使用详细的错误消息更新了我的问题

标签: sirishortcuts


【解决方案1】:

我遇到了同样的错误,因为我不小心在 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
    }
}

【讨论】:

  • 我的应用是一个 SwiftUI,同时具有 Watch、Catalyst 和 iOS 目标。在我的 SiriExtentsions IntentHandler.Swift 中,我调用了 CustomIntentHandler(),但在我的 SiriIntents IntentHandler.Swift 中,它说 CustomIntentHandler() 无效。但它确实接受 CustomIntent()
  • 当我有一个可以接受值的自定义 Intent 时,我似乎收到了这个错误。当我处理没有参数的自定义 Intent 时,它似乎找到了意图处理程序。我在 Intent 定义中使用“默认”值定义了 Intent,这是否需要我更改我的 intentHandler()?
  • 接受这个答案....我现在正在处理一个不同的问题,并将单独提出。
  • @MichaelRowe 您找到自定义意图接受参数问题的解决方案了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-24
  • 1970-01-01
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
  • 2019-04-29
  • 1970-01-01
相关资源
最近更新 更多