Zhang Zhan
Zhang Zhan

Reputation: 905

Cannot add Siri shortcut with "try await appIntent.donate() "

I have the following iOS app code to add AppIntent to Sirishortcut with Swift:

    // Function to Add the Shortcut
    private func suggestShortcut() {
        Task {
            do {
                let intent = MyIntent()
                try await intent.donate()  // Async donation
                print("Shortcut successfully donated.")
            } catch {
                print("Failed to donate shortcut: \(error.localizedDescription)")
            }
        }
    }

And I have the following "MyIntent.swift" code that is generated from "Intents.intentdefinition"

import Foundation
import AppIntents

@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
struct MyIntent: AppIntent, CustomIntentMigratedAppIntent, PredictableIntent {
    static let intentClassName = "MyIntent"

    static var title: LocalizedStringResource = "Tag value"
    static var description = IntentDescription("")

    @Parameter(title: "Tag", default: "My Value")
    var tag: String?

    static var parameterSummary: some ParameterSummary {
        Summary("\(\.$tag) the current value")
    }

    static var predictionConfiguration: some IntentPredictionConfiguration {
        IntentPrediction(parameters: (\.$tag)) { tag in
            DisplayRepresentation(
                title: "\(tag!) the current value",
                subtitle: "Tag the current value"
            )
        }
    }

    func perform() async throws -> some IntentResult {
        // TODO: Place your refactored intent handler code here.
        return .result()
    }
}

@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
fileprivate extension IntentDialog {
    static var tagParameterPrompt: Self {
        "Tag value"
    }
}
@available(iOS 16.0, *)
struct MyShortcuts: AppShortcutsProvider {
    static var appShortcuts: [AppShortcut] {
            AppShortcut(
                intent: MyIntent(tag: IntentParameter(title: "My Value")),
                phrases: [
                    "Tag my value",
                    "Remember my value",
                    "Save my value"
                ],
                shortTitle: "Tag Value",
                systemImageName: "sample.png"
            )
    }
}

Here goes my info.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>AppIntents</key>
    <array>
        <string>MyIntent</string>
    </array>
    <key>AppIntentsEnabled</key>
    <true/>
    <key>IntentsSupported</key>
    <array>
        <string>MyIntent</string>
    </array>
    <key>NSUserActivityTypes</key>
    <array>
        <string>MyIntent</string>
    </array>
</dict>
</plist>

Every time when I call method: suggestShortcut() I can see "Shortcut successfully donated." is printed on the console, however, when I go to Siri shortcuts via opening "shortcuts://shortcuts", I cannot see "Tag Value" on the Siri shortcut list, is there anyone could help me?

Upvotes: 0

Views: 25

Answers (0)

Related Questions