我有这段代码按照注释所指示的顺序执行(根据断点调试):
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)
}
}
意图是在whatsapp上分享UIImage。除了我不理解的奇怪的执行顺序,我得到(因此,我认为)这个错误:
2014-12-11 16:20:09.932 WebViewShareWhatsapp [623:60820] ***断言失败 - [UIDocumentInteractionController setURL:],/ SourceCache / UIKit / UIKit- 3318.16.14 / UIDocumentInteractionController.m:1024
2014-12-11 16:20:09.933 WebViewShareWhatsapp [623:60820] ***由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' UIDocumentInteractionController:无效方案(null) 。仅支持文件方案。'