我正在尝试在我的应用程序的共享扩展中支持消息对话的共享建议。对话建议似乎出现在我的 iPad 上,但没有出现在我的 iPhone 或我测试过的其他几部 iPhone 上。该应用程序是一个通用应用程序。我按照Apple 文档中的说明进行操作。
即使使用最新版本的 xcode(版本 15.3 (15E204a))创建的新项目似乎也存在相同的问题。
捐赠意向代码:
private func donateIntent(chatName: String, chatID: String, groupImage: INImage?) {
let groupName = INSpeakableString(spokenPhrase: chatName)
let intent = INSendMessageIntent(
recipients: nil, outgoingMessageType: .outgoingMessageText, content: nil,
speakableGroupName: groupName, conversationIdentifier: chatID, serviceName: nil, sender: nil,
attachments: nil)
if let groupImage = groupImage {
intent.setImage(groupImage, forParameterNamed: \.speakableGroupName)
}
let interaction = INInteraction(intent: intent, response: nil)
interaction.donate { error in
if let error = error {
print("Error donating intent: \(error)")
} else {
print("Successfully donated sendMessage intent.")
}
}
}
我修改了你的代码。请尝试这个代码它对我有用。
private func donateIntent(chatName: String, chatID: String, groupImage: INImage?) {
let groupName = INSpeakableString(spokenPhrase: chatName)
let intent = INSendMessageIntent(
recipients: nil, content: nil,
speakableGroupName: groupName, conversationIdentifier: chatID, serviceName: nil, sender: nil,
attachments: nil)
if let groupImage = groupImage {
intent.setImage(groupImage, forParameterNamed: \.speakableGroupName)
}
let interaction = INInteraction(intent: intent, response: nil)
interaction.donate { error in
if let error = error {
print("Error donating intent: \(error)")
} else {
print("Successfully donated sendMessage intent.")
}
}
}