【发布时间】:2018-07-11 20:44:34
【问题描述】:
我正在尝试将我的 ios 应用程序中的音频文件共享到 whatsapp,但直接打开 whatsapp,而不是打开所有磁贴的共享菜单。
这是我现在拥有的:
// Getting the original file
let fileName = #MY FILE NAME#
let filePath = Bundle.main.path(forResource: fileName, ofType: "mp3")!
let urlData = URL.init(fileURLWithPath: filePath)
let nsData = NSData(contentsOf: urlData)
if (nsData != nil){
// Creating the temporary file to share in the accessible ressources
let newFileName = "file.mp3"
let newFilePath = "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/\(newFileName)"
nsData?.write(toFile: newFilePath, atomically: true)
let newUrlData = URL.init(fileURLWithPath: newFilePath)
// Sharing the file to whatsapp
// Possibility 1 (does not work yet)
// let documentController = UIDocumentInteractionController(url: newUrlData)
// documentController.uti = "net.whatsapp.audio"
// documentController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
// Possibility 2 (works only with the sharing menu)
let activityVC = UIActivityViewController(activityItems: [NSURL(fileURLWithPath: newFilePath)], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
}
当我这样做时,将音频文件共享到 whatsapp 是可行的,但它首先会打开共享菜单,其中包含信使磁贴、消息磁贴、注释磁贴……(它不适用于信使应用程序) .最后,我希望能够在 Messenger 和 whatsapp 上分享。
As explicated here in the whatsapp documentation,我想在分享文件的时候直接打开whatsapp应用:
或者,如果您只想在应用程序列表中显示 WhatsApp(而不是 WhatsApp 以及任何其他公共/*符合标准的应用程序),您可以指定使用 WhatsApp 独有的扩展名保存的上述类型之一的文件:
- 图像 - «.wai»,类型为 net.whatsapp.image
- 视频 - «.wam» 类型为 net.whatsapp.movie
- 音频文件 - «.waa»,类型为 net.whatsapp.audio
触发后,WhatsApp 将立即向用户展示联系人/群组选择器屏幕。媒体将自动发送到选定的联系人/组。
所以我尝试换行:
let newFileName = "file.mp3"
其中之一:
let newFileName = "file.mp3.waa"
let newFileName = "file.waa"
let newFileName = "file.waa.mp3"
但它仍然显示相同的共享菜单(如果以 .waa 扩展名结尾,则无法读取音频文件)。
-> 1) 可以做我想做的事吗?
-> 2) 如果没有,有没有办法分享给 messenger 和 whatsapp,使用相同的代码保持一个共享菜单
-> 3)如果没有,有没有办法根据不同的调用事件将共享菜单减少到只有一个图块,这样就不会混淆选择图块
谢谢, 安托万
【问题讨论】:
-
嗨,您能找到直接在 whatsapp Messenger 或 instagram 上共享音频的任何解决方案吗???
标签: ios xcode audio share whatsapp