Sharing images to Whatsapp using UIDocumentIntractionController in ios

我与影子孤独终老i 提交于 2019-12-23 03:06:20

问题


Is it possible to share Image and Text from an iOS app to WhatsApp using UIDocumentIntractionController or API in iPhone application development?


回答1:


Please look at this once.

http://www.whatsapp.com/faq/en/iphone/23559013

Hope, this will help you.

All the best.




回答2:


Hi i have found that If your application creates photos, videos or audio notes and you’d like your users to share these media using WhatsApp, you can use the Document Interaction API to send your media to your WhatsApp contacts and groups.

You can refer this link : http://www.whatsapp.com/faq/en/iphone/23559013




回答3:


In Swift 3 use this code

 @IBAction func whatsappShareWithImages(_ sender: AnyObject)
    {

        let urlWhats = "whatsapp://app"
        if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed) {
            if let whatsappURL = URL(string: urlString) {

                if UIApplication.shared.canOpenURL(whatsappURL as URL) {

                    if let image = UIImage(named: "whatsappIcon") {
                        if let imageData = UIImageJPEGRepresentation(image, 1.0) {
                            let tempFile = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/whatsAppTmp.wai")
                            do {
                                try imageData.write(to: tempFile, options: .atomic)
                                self.documentInteractionController = UIDocumentInteractionController(url: tempFile)
                                self.documentInteractionController.uti = "net.whatsapp.image"
                                self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

                            } catch {
                                print(error)
                            }
                        }
                    }

                } else {
                    // Cannot open whatsapp
                }
            }
        }

    }

Add this code in your app "plist"

  <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>whatsapp</string>
    </array>

You can also refer to small app for reference : https://github.com/nithinbemitk/iOS-Whatsapp-Share



来源:https://stackoverflow.com/questions/14193853/sharing-images-to-whatsapp-using-uidocumentintractioncontroller-in-ios

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