Implemented iOS AppIntents don't show in Shortcuts

2.6k Views Asked by At

I'm trying to test out the new AppIntents API that is currently on iOS16 Beta. Looking at the documentation, the implementation seems pretty straight forward, but after implementing it, I'm not seeing my AppIntent in the Shortcuts app. The device is running iOS 16.0.

This is how I implemented the AppIntent:


import AppIntents

struct DoSomethingIntent: AppIntent {
    
    static var title: LocalizedStringResource = "This will do something"
    
    static var description = IntentDescription("Does something")
    
    func perform() async throws -> some PerformResult {
        return .finished(value: "Done")
    }
}

According to the documentation the Shortcuts app should be able to find my AppIntent after my app gets installed, but I see that's not the case. Does anybody know what my implementation is missing?

4

There are 4 best solutions below

0
On

turn to compiler for help, cuz the appintents is generate by compiler. when it comes to intent file, it generate a task

SwiftDriverJobDiscovery normal arm64 Compiling intent.swift 

then the appintentsmetadataprocessor will generate the Metadata.appintents file into the bundle

check the build log, to see if the processor works well.

it should make sense :)

0
On

The API is very bugged. Use the old SiriKit Intents.intentdefinition file (CMD+N to create it) to set up your intents with the dedicated UI then select the option Convert to App Intent to generate the App Intents with an implementation that actually works and adjust as your needs. Intent definition file

Then in the Shortcuts provider use these intents and remember to interpolate the phrases with .applicationName otherwise it won't appear in the Shortcuts app.

struct Shortcuts: AppShortcutsProvider {

static var shortcutTileColor: ShortcutTileColor = .navy

static var appShortcuts: [AppShortcut] {
    AppShortcut(intent: SomeIntent(),
                phrases: ["Do something with \(.applicationName)"],
                shortTitle: "Just do it",
                systemImageName: "magnifyingglass")
}

}

0
On
  • First you need to select your Xcode-beta.app via xcode-select

  • Clean derived data

  • Kill your app & shortcut app

  • Add a shortcut library in your code

struct LibraryAppShorcuts: AppShortcutsProvider {
    @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
        AppShortcut(intent: DoSomethingIntent(), phrases: ["My something phrase"])
    }
}
  • Build
2
On

AppIntents APIs are a little bit new and have strange behaviours and the documentation is very poor.

In my case, I was able to make them work by adding the \(.applicationName) parameter to the phrase. Try this:

struct LibraryAppShorcuts: AppShortcutsProvider {
    @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
        AppShortcut(intent: DoSomethingIntent(), phrases: ["Do something with \(.applicationName)"])
    }
}