支持分享 Sheet 条建议

Supporting Share Sheet Suggestions

在此之后 article 我正在尝试在我的消息应用程序中实施分享 sheet 建议。

我已在我的共享扩展 info.plist 中声明 INSendMessageIntent 支持。

它甚至出现在 'Supported Intents' 下的目标中。

但是每次我捐赠 INSendMessageIntent 时它都会失败,说 INSendMessageIntent 不受支持。

Error Domain=IntentsErrorDomain Code=1901 "Donating intent 'INSendMessageIntent' is not supported by this extension. Please make sure that you declare the intents that your app supports by including the NSUserActivityTypes key in its Info.plist or your app contains an Intents extension that supports this intent."

// Create an INSendMessageIntent to donate an intent for a conversation with Juan Chavez.
let groupName = INSpeakableString(spokenPhrase: "Juan Chavez")
let sendMessageIntent = INSendMessageIntent(recipients: nil,
                                            content: nil,
                                            speakableGroupName: groupName,
                                            conversationIdentifier: "sampleConversationIdentifier",
                                            serviceName: nil,
                                            sender: nil)

// Add the user's avatar to the intent.
let image = INImage(named: "Juan Chavez")
sendMessageIntent.setImage(image, forParameterNamed: \.speakableGroupName)

// Donate the intent.
let interaction = INInteraction(intent: sendMessageIntent, response: nil)
interaction.donate(completion: { error in
    if error != nil {
        // Add error handling here.
    } else {
        // Do something, e.g. send the content to a contact.
    }
})

您应该将 NSUserActivityTypes 条目添加到您应用的 Info.plist。将其声明为数组并将您的意图添加到其中。