我正在为 iMessage 编写一个应用程序,并希望在用户点击 imessage 应用程序屏幕时自动发送消息。
该消息由位置地址的 map 组成。
最初,我尝试使用message.url 来包含maps.apple.com url,这样当接收者点击收到的消息时,它就会打开 map 。
但这似乎不起作用。所以我尝试单独发送地址:首先是图像,然后是地址。然后,接收者可以点击地址, map 就会打开。
我有以下代码:
if let image = createImageForMessage(), let conversation = activeConversation {
let layout = MSMessageTemplateLayout()
layout.image = image
let message = MSMessage()
message.layout = layout
//conversation.insert(message, completionHandler: nil)
//conversation.insertText("We are at:\n" + addressLabel, completionHandler: nil)
conversation.send(message, completionHandler: nil)
conversation.sendText("We are at:\n" + addressLabel, completionHandler: nil)
}
理想情况下,我希望只需要初始点击,但使用“send”和“sendText”仅发送第一个“send”指令,“sendText”将被忽略。
如果我使用注释掉的“insert”和“insertText”,那么这两个指令都会执行,但我必须点击“send”才能发送它。
我已经尝试过:
conversation.insert(message, completionHandler: nil)
conversation.sendText("We are at:\n" + addressLabel, completionHandler: nil)
但这没有用。仅发送了文本。图像根本不显示。
有人知道如何一键发送两条消息吗?
或者,有谁知道我是否可以将这两条消息合并为一条消息?
最佳答案
从 MSConversation
的文档来看,您似乎不能同时有两条待处理消息。
我会尝试:
conversation.insert(message, completionHandler: ^{
conversation.sendText("We are at:\n" + addressLabel, completionHandler: nil)
})
关于ios - 使用 Swift 在 iMessage 中发送多条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827017/