ios – How to call an intent from widget in SwiftUI


I am trying to add play music button to my widget. However, I get

“Could not find an intent with identifier PlayerIntent,
mangledTypeName: Optional(“21PlayerWidgetExtension0A6IntentV”)”

error. I added PlayerIntent to both app and widget targets.

struct PlayerIntent: AudioStartingIntent {
static var title: LocalizedStringResource = "PlayerIntent"
static var description: IntentDescription = IntentDescription("Plays a widget sound")

@Parameter(title: "Sound")
var sound: String

init() {}

init(sound: String) {
    self.sound = ""
}

@MainActor
func perform() async throws -> some IntentResult {
    Player.shared.play()
    return .result()
}}

I created PlayerIntent by adding an “App Intents Extensions” target. Otherwise, I can’t even see this error in console.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img