I am adding siri Shortcuts to my existing app. There are three shortcuts, one to start the app with a specific value, one to increase the value by an amount and one to decrease the value by an amount. The shortcut code, for the start the app is attached here:
//
// 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))
}
}
}
When I run the shortcut from the Shortcuts app, I get the message "An unknown error has occurred". How does one go about debugging that?
After reviewing the console for the simulator I found two errors: 1)
[INCExtensionRequest _extensionContextHost] Unexpected extension context class (null)
and 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}
I had this exact same error because I was accidentally returning my CustomIntent instead of my CustomIntentHandler in the IntentHandler.swift file
Before:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
if intent is CustomIntent {
return CustomIntent()
}
return self
}
}
After:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
if intent is CustomIntent {
return CustomIntentHandler()
}
return self
}
}