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.'