Adding intent to the AppIntentsExtension

51 Views Asked by At

I have added an "App Intents Extension" target to my main application in macOS. This generated the below two files:

TWAppIntent.swift

import AppIntents
    
struct TWAppIntent: AppIntent {
    static var title: LocalizedStringResource = "TWAppIntent"
    static var parameterSummary: some ParameterSummary {
        Summary("Get information on \(\.$TWType)")
    }
        
    @Parameter(title: "TWType")
    var TWType: String
        
    func perform() async throws -> some IntentResult {         
        return .result(dialog: "Executed TWAppIntent.")
    }
}

TWAppIntentExtension.swift

import AppIntents
    
@main
struct TWAppIntentExtension: AppIntentsExtension {
        
}

I m able to build the extension target and I my intent action is available in the shortcuts app. However, on launching a shortcut with the above created intent action. I m getting the below popups:

enter image description here enter image description here

From what I understand, I m getting this error because I have not added my 'TWAppIntent' to the TWAppIntentExtension.swift file which is the entry point for the extension, but I could not find any documentation around how to add it. Can someone help on how to do it or Is there something else that I m doing wrong?

1

There are 1 best solutions below

0
alessionossa On

To debug App Intents and find out what’s the actual error behind the generic one you are saying, it’s very useful to use the Console app on macOS, stream your device's logs and filter the output with the name of your app: you will often find detailed errors.

In this case, the error is most likely that you are providing a dialog without specifying ProvidesDialog in the return type of perform()

    func perform() async throws -> some IntentResult & ProvidesDialog {
        return .result(dialog: "Executed TWAppIntent.")
    }

It used to be more flexible on iOS 16, but with iOS 17, according also to App Intent definition changed, but it is not synced to the Shortcuts app, you have to specify what you want to return.