7

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?

YodagamaHeshan
  • 4,996
  • 2
  • 26
  • 36
Norik
  • 161
  • 1
  • 9
  • The “signatures” for any AppIntents/Shortcuts in your app get cached somewhere(?) by the system. Any time that you make a change to your intents (or your `AppShortcutsProvider`), you’ll need to delete your app (Xcode -> Product -> Clean Build Folder…), and quit and restart the Shortcuts app (macOS) or restart the simulator (iOS/iPadOS). You may need to repeat that once or twice to get the system to notice that its cache is out of date. – Grant Neufeld Jul 10 '23 at 03:07
  • Not sure if this was a change since the beta, but you should try to change the perform() action to [`return .result()`](https://developer.apple.com/documentation/appintents/intentresult/result()) or [`return .result(value: "Done")`](https://developer.apple.com/documentation/appintents/intentresult/result(value:)). – alexkaessner Aug 08 '23 at 09:00

3 Answers3

8

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)"])
    }
}
jmartinalonso
  • 2,324
  • 1
  • 19
  • 22
  • With iOS 17 beta and Xcode 15.0 beta 4, I was able to get my first intent to appear by adding applicationName as indicated above. I did not need to clean my build folder, delete my app, restart my app, the Shortcuts app, or my Mac or my iPad mini. – bruce1337 Jul 25 '23 at 08:00
  • Theoretically, this shouldn’t be necessary to do! Using the `AppShortcutsProvider` will add the shortcut to Spotlight and as _a suggestion_ in the Shortcuts app. Though, you don’t have to do this if you want to simply add a shortcut action to the Shortcuts app. – alexkaessner Aug 08 '23 at 08:54
2
  • 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
bourvill
  • 152
  • 1
  • 13
0

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")
}

}

zouritre
  • 231
  • 3
  • 6