0

I'm trying to share a simple .txt file to WhatsApp using UIDocumentInteractionController on iOS.

I found this FAQ of WhatsApp explaining the Custom URL Scheme for WhatsApp, but it is not explaining how to share another document to WhatsApp. This should be possible with a WhatsApp update released about 2 months ago.

I also found this answer, but it does not work for other document types. Can anyone help me?

My code, that does not work, because the URL Scheme is wrong:

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

  activityVc = UIDocumentInteractionController(url: URL(fileURLWithPath: txtPath))
  activityVc.uti = "net.whatsapp.document"
  activityVc.presentOptionsMenu(from: CGRect.zero, in: self.view, animated: true)
  }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Mojo
  • 377
  • 6
  • 18
  • Please post what you have tried and narrow down the explanation of what isn't working. Check out https://stackoverflow.com/help/how-to-ask – brandonscript Oct 13 '17 at 18:39
  • I added my code. Maybe this can help someone... – Mojo Oct 13 '17 at 18:55
  • Are you sure it's possible? The page you link to mentions some `net.whatsapp.*` schemes but not `net.whatsapp.document`. – Tom Harrington Oct 13 '17 at 19:17
  • Yes I am, because whatsapp posted in their change log, that you can now share any kind of document. On Android it is working ;) – Mojo Oct 13 '17 at 19:22

0 Answers0