Send Image and Text With Whatsapp

荒凉一梦 提交于 2019-12-04 10:15:13
Niraj

You can post Image or Text on WhatsApp. However you can't post both at a time as whatsapp does not provide any API that you can add caption and post image with text.

Now there is an api available for interacting with WhatsApp:

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

Also Find below helpful answer:

You can use the UIDocumentInteractionController as mentioned in the 2nd answer to this question as of August 4, 2014: Share image/text through WhatsApp in an iOS app

Hope this will help.

A version of your share image code for swift 3:

let image = myUIImageVariable
        let filename = "myimage.wai"
        let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, false)[0] as NSString
        var destinationPath = documentsPath.appending("/" + filename) as NSString
         destinationPath = destinationPath.expandingTildeInPath as NSString

        let fileUrl = NSURL(fileURLWithPath: destinationPath as String) as NSURL
        do{
            try UIImagePNGRepresentation(image!)?.write(to: fileUrl as URL, options: Data.WritingOptions.atomic)
        }
        catch {}
        let documentController = UIDocumentInteractionController(url: fileUrl as URL)
        documentController.delegate = self
        documentController.uti = "net.whatsapp.image"
        documentController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: false)

Still does not seem work even for just sharing an image, but may save someone's time

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