gpt4 book ai didi

ios - XCODE/IOS-通过直接打开将音频文件共享到whatsapp

转载 作者:行者123 更新时间:2023-12-03 01:39:32 25 4
gpt4 key购买 nike

我试图将音频文件从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)如果没有,则有一种方法可以根据不同的 call 事件将共享菜单减少到一个图块,因此不会混淆图块的选择

谢谢,
安托万

最佳答案

cf:XCODE / IOS - How to use exclusive extension to immediately present whatsapp (.wai, .waa, .wam)

仅供引用:随着我对此进行了大量测试,我找不到任何解决方案。

Whatsapp可以识别文件扩展名,但无法读取。共享后,当您单击它时,它被写为“.whatsapp音频文件”,仅此而已(甚至不直接共享)。

我给whatsapp开发人员团队发送了一封电子邮件,他们说他们目前还有其他问题需要解决,因此甚至不在他们的待办事项 list 上。

等着瞧..

关于ios - XCODE/IOS-通过直接打开将音频文件共享到whatsapp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48564209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com