ios - 如何将音频文件加载到 IMessage ios 10?

标签 ios swift imessage xcode8 ios10

所以我一直在玩新的 xcode 8 beta,我能够将图像加载到 .image 属性中,但我没有成功加载具有 .mediaFileURL 属性的音频文件。 这是我的

var message = MSMessage() 
var template = MSMessageTemplateLayout()

viewDidLoad() {    
     if let filePath2 =
     Bundle.main().pathForResource("synth", ofType: "wav") {
         let fileUrl = NSURL(string: filePath2)
         let URL2 = fileUrl as! URL
         template.mediaFileURL = URL2
     }

     message.layout = template

     guard let conversation = activeConversation else {

     fatalError("Expected a conversation") }  conversation.insert(message,
         localizedChangeDescription: nil) { error in
         if let error = error {
             print(error)
         }
     }
}

最佳答案

根据漏洞报告者的说法,我应该使用 insertAttachment API 来插入 MP3、WAV 和 M4a。

conversation.insertAttachment(fileUrl, withAlternateFilename: "fileAudio") { error in
        if let error = error {
            print(error)
        }

关于ios - 如何将音频文件加载到 IMessage ios 10?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37914493/

相关文章:

ios - Apple Pay P2P (iOS 11) - 2017 年秋季是否会有此 SDK?

ios - 如何在 iOS 的弹出窗口中打开相机胶卷?

ios - 如何更新自动续订订阅收据

iphone - UISearchBar 右对齐放大镜图标

ios - UICollectionView SupplementaryView 将 UIButton 添加到页脚

json - 无法解码 token : The token ###

ios - 应用程序处理失败并显示消息 "This build is invalid."

ios - 打开方向功能不以编程方式打开苹果 map

ios - iMessage 扩展是否需要 iOS10 中的容器(父)应用程序?

ios - 导航栏不出现