在使用UIDocumentInteractionController时,迅速捣毁“在Instagra
我有以下代码,用于从
Swift应用程序在instagram上共享图像:
@IBAction func instagramShareButton(sender:AnyObject){ let documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] as NSString let path = documentsDirectory.stringByAppendingPathComponent("Share Icon.igo") let imageName: String = "Share Icon.png" let image = UIImage(named: imageName) let data = UIImagePNGRepresentation(image!) data!.writeToFile(path,atomically: true) let imagePath = documentsDirectory.stringByAppendingPathComponent("Share Icon.igo") let rect = CGRectMake(0,0) UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,self.view.opaque,0.0) self.view.layer.renderInContext(UIGraphicsGetCurrentContext()!) UIGraphicsEndImageContext() let fileURL = NSURL(fileURLWithPath: imagePath) print("fileURL = (fileURL)") var interactionController = UIDocumentInteractionController(URL: fileURL) interactionController.delegate = self interactionController.UTI = "com.instagram.exclusivegram" let msgBody = "My message" interactionController.annotation = NSDictionary(object: msgBody,forKey: "InstagramCaption") interactionController.presentOpenInMenuFromRect(rect,inView: self.view,animated: true) } func documentInteractionControllerWillPresentOpenInMenu(controller:UIDocumentInteractionController){ 代码从Objective C转换为Swift,因为我没有在Swift中发现任何东西在Instagram上分享. 菜单弹出,我看到instagram在那里,当我点击它,我得到以下错误:
我相信我不得不释放UIDocumentInteractionController对象.我对吗?
我想你是对的
我有同样的问题. 在开始共享功能之前,必须从UIDocumentInteractionController创建一个全局变量: var interactionController: UIDocumentInteractionController? @IBAction func instagramShareButton(sender: AnyObject) { ... interactionController = UIDocumentInteractionController(URL: fileURL) interactionController!.UTI = "com.instagram.exclusivegram" let msgBody = "My message" interactionController!.annotation = NSDictionary(object: msgBody,forKey: "InstagramCaption") interactionController!.presentOpenInMenuFromRect(rect,animated: true) } 这对我有用 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |