【问题标题】:Supporting Share Sheet Suggestions支持共享表建议
【发布时间】:2020-04-20 14:28:18
【问题描述】:

在此article 之后,我正在尝试在我的消息传递应用程序中实施共享表建议。

我已在我的 Share 扩展程序的 info.plist 中声明支持 INSendMessageIntent

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

但每次我捐赠 INSendMessageIntent 时,都会显示不支持 INSendMessageIntent

Error Domain=IntentsErrorDomain Code=1901 "此扩展不支持捐赠意图 'INSendMessageIntent'。请确保通过在 Info.plist 中包含 NSUserActivityTypes 键来声明您的应用支持的意图,或者您的应用包含支持此意图的意图扩展。”

// 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.
    }
})

【问题讨论】:

  • 我看到了同样的错误信息,但是 - let interaction = INInteraction(intent: addAttendeeIntent, response: nil) interaction.donate { (error) in if error != nil { if let error =错误为 NSError? { print("发生错误:(error)") } } else { print("添加参加者意图成功") } }

标签: ios swift ios-app-extension share-extension


【解决方案1】:

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

【讨论】:

  • 就是这样!非常感谢!苹果真的应该把它添加到他们的指南中。
  • 你是添加到 App plist 还是 ShareExtension plist 中?
猜你喜欢
  • 1970-01-01
  • 2019-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多