0

I have this piece of code which executes in the order indicated by the comments (according to breakpoint debugging):

func openShareSheet() {

    if( UIApplication.sharedApplication().canOpenURL(NSURL(string:"whatsapp://app")!) ){

        let tSavePath = NSHomeDirectory() + "Documents/whatsAppTmp.wai" // 1

        UIImageJPEGRepresentation(appDelegate.image!, 1.0)
          .writeToFile(tSavePath, atomically: true) // 3

        documentInteractionController = 
          UIDocumentInteractionController(URL: NSURL(string: tSavePath)!) // 4: Crash, see error message below
        documentInteractionController.UTI = "net.whatsapp.image" // 2
        documentInteractionController.delegate = self

        documentInteractionController
          .presentOpenInMenuFromRect(CGRectMake(0, 0, 0, 0), inView: 
          self.view, animated: true)  
    }         
}

The Intent is to share an UIImage on whatsapp. Apart from the weird execution order I dont understand, I get (as a result, I assume) this error:

2014-12-11 16:20:09.932 WebViewShareWhatsapp[623:60820] *** Assertion failure in - [UIDocumentInteractionController setURL:], /SourceCache/UIKit/UIKit- 3318.16.14/UIDocumentInteractionController.m:1024

2014-12-11 16:20:09.933 WebViewShareWhatsapp[623:60820] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController: invalid scheme (null). Only the file scheme is supported.'

halfer
  • 19,824
  • 17
  • 99
  • 186
最白目
  • 3,505
  • 6
  • 59
  • 114
  • 1
    FYI, Stepping through the code will not reveal the true order of line execution. – Daniel T. Dec 11 '14 at 15:25
  • oh thats good to hear, that means I can stop punching my head against the wall for now. – 最白目 Dec 11 '14 at 15:30
  • Don't use the `NSHomeDirectory()` but get the path to the document directory and never just append a path component. See this exact same question in `Objective-C`: http://stackoverflow.com/questions/27380656/whatsapp-image-sharing-not-working/27381461#27381461 Is this form some kind of homework? – rckoenes Dec 11 '14 at 15:39
  • the linked answer helped me, thank you too. – 最白目 Dec 11 '14 at 15:57
  • Possible duplicate of [Whatsapp Image sharing not working](https://stackoverflow.com/questions/27380656/whatsapp-image-sharing-not-working) – staticVoidMan May 31 '18 at 23:54

0 Answers0