我正在创建 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
没有将任何文件添加到消息中。
当我尝试使用上面的代码发送文件时,它看起来如下所示:
它看起来不错,但没有音频可播放,但如果我尝试这种方式:
let destinationFilename = mp3FileNames[i]
let destinationURL = docDirectoryURL.appendingPathComponent(destinationFilename)
if let conversation = activeConversation {
conversation.insertAttachment(destinationURL!, withAlternateFilename: nil, completionHandler: nil)
return
}
上面代码的结果是:
我可以播放该消息的音频,因为它就在那里。但该消息的问题是我无法附加任何图像或标题。
如何将图像和音频文件附加到同一封邮件中。
如果可能的话,我可以添加 GIF 而不是图像吗?
非常感谢任何帮助,谢谢。
最佳答案
无需使用GIF
,iMessage
扩展还支持PNG
和JPEG
图像格式。建议的图像大小为 300x300 点,@3x 比例。
如果 MSMessageTemplateLayout
的 image
属性具有非 nil 值,则
mediaFileURL
属性被忽略。所以你不能同时发送图像和音频文件。 Docs
关于swift - 如何在 iOS 10 的 iMessage 应用程序中发送带有图像和标题的音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39073714/