Adding intent to the AppIntentsExtension

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)")
    }
    
    // we can have multiple parameter of diff types
    @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:

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?

Answered by katebrr in 781238022

Hey!

I added your AppIntent to my AppIntentExtension and the problem isn't the @main the problem is that as soon as your app intent calls perform it crashes

The big issue with AppIntentExtension that it is impossible to debug it. So if your app succeeded to extract metadata it means the rest fails on your interactions , it may help you later to trace the errors which unfortunately for now we can't see.

Let's get back to your AppIntent, it crashes your app and your extension because your result returns dialog, which you didn't precise in return type of your perform.

Adding ProvidesDialog solve the problem.

Good luck:)

I've encountered the same issue before and found a solution. If you remove the extension and integrate your TWTAppIntent code directly into the main app target without the @main TWTAppIntentExtension, you should be able to resolve it. This is the approach I previously used and it worked effectively.

However, if you prefer to continue using the AppIntent in the custom extension, I suspect the error may originate from the TWTAppIntentExtension itself. It appears to be an empty main-entry, but this is just speculation on my part.

Accepted Answer

Hey!

I added your AppIntent to my AppIntentExtension and the problem isn't the @main the problem is that as soon as your app intent calls perform it crashes

The big issue with AppIntentExtension that it is impossible to debug it. So if your app succeeded to extract metadata it means the rest fails on your interactions , it may help you later to trace the errors which unfortunately for now we can't see.

Let's get back to your AppIntent, it crashes your app and your extension because your result returns dialog, which you didn't precise in return type of your perform.

Adding ProvidesDialog solve the problem.

Good luck:)

Adding intent to the AppIntentsExtension
 
 
Q