XCODE / IOS - 直接打开分享音频文件到whatsapp
XCODE / IOS - Share audio file to whatsapp with a direct opening
我正在尝试将音频文件从我的 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 磁贴、消息磁贴、便笺磁贴...(它不适用于 Messenger应用程序)。最后,我希望能够在 Messenger 和 whatsapp 上分享。
As explicated here in the whatsapp documentation,我想分享文件的时候直接打开whatsapp应用程序:
Alternatively, if you want to show only WhatsApp in the application list (instead of WhatsApp plus any other public/*-conforming apps) you can specify a file of one of aforementioned types saved with the extension that is exclusive to WhatsApp:
- images - «.wai» which is of type net.whatsapp.image
- videos - «.wam» which is of type net.whatsapp.movie
- audio files - «.waa» which is of type net.whatsapp.audio
When triggered, WhatsApp will immediately present the user with the contact/group picker screen. The media will be automatically sent to a selected contact/group.
所以我尝试更改行:
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 识别文件扩展名,但甚至无法读取它。一旦分享,当你点击它时,它被写成“.whatsapp音频文件”,仅此而已(甚至没有直接分享)。
我给 whatsapp 开发团队发了一封电子邮件,他们说他们目前还有其他问题需要解决,所以这甚至不在他们的待办事项列表中。
拭目以待..
我正在尝试将音频文件从我的 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 磁贴、消息磁贴、便笺磁贴...(它不适用于 Messenger应用程序)。最后,我希望能够在 Messenger 和 whatsapp 上分享。
As explicated here in the whatsapp documentation,我想分享文件的时候直接打开whatsapp应用程序:
Alternatively, if you want to show only WhatsApp in the application list (instead of WhatsApp plus any other public/*-conforming apps) you can specify a file of one of aforementioned types saved with the extension that is exclusive to WhatsApp:
- images - «.wai» which is of type net.whatsapp.image
- videos - «.wam» which is of type net.whatsapp.movie
- audio files - «.waa» which is of type net.whatsapp.audio
When triggered, WhatsApp will immediately present the user with the contact/group picker screen. The media will be automatically sent to a selected contact/group.
所以我尝试更改行:
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 识别文件扩展名,但甚至无法读取它。一旦分享,当你点击它时,它被写成“.whatsapp音频文件”,仅此而已(甚至没有直接分享)。
我给 whatsapp 开发团队发了一封电子邮件,他们说他们目前还有其他问题需要解决,所以这甚至不在他们的待办事项列表中。
拭目以待..