How to share video on WhatsApp without using UIActivityViewController?

不问归期 提交于 2020-05-15 09:08:10

问题


I am currently trying to enable the functionality to share a video on WhatsApp but without using UIActivityViewController, as Tik Tok does for example. When you click on "share" on WhatsApp, it directly redirects you to WhatsApp and contacts pop up so that you can share the video.

I kinda succeeded in sharing it but with ActivityViewController, this way:

 let path = Bundle.main.url(forResource: "Rap God", withExtension: "mp4")!.relativePath
 let fileUrl = NSURL(fileURLWithPath: path)
 controller = UIDocumentInteractionController(url: fileUrl as URL)
 controller.uti = "net.whatsapp.movie"
 controller.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

I would be glad to know someone can help me out.


回答1:


Try using UIApplication's canOpenURL(_:) and open(_:options:completionHandler:),

let urlString = "https://stackoverflow.com/questions/60282744/how-to-share-video-on-whatsapp-without-using-uiactivityviewcontroller"
let shareString = "whatsapp://send?text=\(urlString)"
if let url = URL(string: shareString), UIApplication.shared.canOpenURL(url)  {
    UIApplication.shared.open(url, options: [:]) { (completed) in
        print(completed)
    }
}


来源:https://stackoverflow.com/questions/60282744/how-to-share-video-on-whatsapp-without-using-uiactivityviewcontroller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!