swift - 如何在 iOS 10 的 iMessage 应用程序中发送带有图像和标题的音频文件?

标签 swift swift3 ios10 imessage ios-messages-extension

我正在创建 iMessage 应用程序并尝试将音频或视频文件发送给其他用户。

视频文件可以正常工作并且看起来不错,但它不能像预期的那样与音频文件一起工作。

我当前的代码是:

let destinationFilename = mp3FileNames[i]
let destinationURL =  docDirectoryURL.appendingPathComponent(destinationFilename)

if let conversation = activeConversation {

    let layout = MSMessageTemplateLayout()
    layout.image = UIImage.init(named: "audio-x-generic-icon")
    layout.mediaFileURL = destinationURL
    layout.caption = selectedSongObj.name

    let message = MSMessage()
    message.layout = layout
    message.url = URL(string: "emptyURL")

    conversation.insert(message, completionHandler: nil)


    return
}

看起来 layout.mediaFileURL = destinationURL 没有将任何文件添加到消息中。

当我尝试使用上面的代码发送文件时,它看起来如下所示:

enter image description here

它看起来不错,但没有音频可播放,但如果我尝试这种方式:

let destinationFilename = mp3FileNames[i]
let destinationURL =  docDirectoryURL.appendingPathComponent(destinationFilename)

if let conversation = activeConversation {

    conversation.insertAttachment(destinationURL!, withAlternateFilename: nil, completionHandler: nil)
    return
}

上面代码的结果是:

enter image description here

我可以播放该消息的音频,因为它就在那里。但该消息的问题是我无法附加任何图像或标题。

如何将图像和音频文件附加到同一封邮件中。

如果可能的话,我可以添加 GIF 而不是图像吗?

非常感谢任何帮助,谢谢。

最佳答案

无需使用GIFiMessage 扩展还支持PNGJPEG 图像格式。建议的图像大小为 300x300 点,@3x 比例。

如果 MSMessageTemplateLayoutimage 属性具有非 nil 值,则 mediaFileURL 属性被忽略。所以你不能同时发送图像和音频文件。 Docs

关于swift - 如何在 iOS 10 的 iMessage 应用程序中发送带有图像和标题的音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39073714/

相关文章:

swift - 如何在 Swift 3 中访问 CFDictionary?

ios - 当应用程序处于焦点状态时,无法将 OneSignal 通知显示为横幅 :iOS

xcode - 我可以在 iOS 10 发布之前提交 iOS 10 应用程序以供审核吗?

swift - 如何在 Swift 中添加两个泛型值?

ios - Swift - 将数据从 TableView xib 文件传递​​到 View Controller

ios - 在 Swift 中带有超链接文本的 UITextView

ios - swift 。谷歌地图 View 显示问号而不是字母

ios - 索引超出范围数据 nil swift 3

ios - 为什么在延迟调用时循环迭代有时会被打乱? [代码和输出]

ios - 我是否必须做一些特别的事情才能让 TestFlight 构建使用我的通知扩展目标?它被忽略了