ios - 使用 Swift 在 iMessage 中发送多条消息

标签 ios swift send imessage-extension msmessage

我正在为 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/

相关文章:

ios - UIStepper不会注册任何事件

ios - 将 IPA 上传到 App Store 时出错

ios - 如何在滑动时隐藏tableView? swift

ios - 如何以编程方式创建带有动态选项卡的选项卡栏?底部黑屏问题

java - 发送命令到http服务器

C套接字编程: client send() but server select() doesn't see it

ios - 如何自定义分组表格 View 单元格的背景/边框颜色?

ios - 快照缩放的 UIView

swift - PDFPage 的 "setBounds"不裁剪应用于 pdfpage 的注释

c#,尝试发送消息,如果离线自动休眠,重新连接,重新发送