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

问题描述 投票:13回答:1

我正在创建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吗?

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

swift swift3 ios10 imessage ios-messages-extension
1个回答
8
投票

没有必要使用GIFiMessage扩展支持PNGand和JPEG图像格式。推荐图像尺寸为300x300点,@ 3x刻度。

如果MSMessageTemplateLayoutimage属性具有非零值,则忽略mediaFileURL属性。因此,您无法同时发送图像和音频文件。 Docs

© www.soinside.com 2019 - 2024. All rights reserved.