这在iOS 8上运行良好,但在iOS 9上,UIDocumentInteractionController确实出现了Copy to Instagram选项。按下它只是取消控制器。
任何反馈都将不胜感激。
谢谢,
var docController = UIDocumentInteractionController()
let instagramURL = NSURL(string: "instagram://app")
if(UIApplication.sharedApplication().canOpenURL(instagramURL!)) {
var imagePost = cropped
let fullPath = documentsDirectory().stringByAppendingString("insta.igo")
var imageData = UIImagePNGRepresentation(imagePost!)!.writeToFile(fullPath, atomically: true)
let rect = CGRectMake(0, 0, 0, 0)
self.docController.UTI = "com.instagram.exclusivegram"
let igImageHookFile = NSURL(string: "file://\(fullPath)")
self.docController = UIDocumentInteractionController(URL: igImageHookFile!)
self.docController.presentOpenInMenuFromRect(rect, inView: self.view, animated: true)
}
func documentsDirectory() -> String {
let documentsFolderPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
return documentsFolderPath
}
答案 0 :(得分:3)
我想出来并留在这里以防其他人有这个问题。
iOS9在声明" insta.igo"时读取它的方式,现在需要有" /"
let fullPath = documentsDirectory().stringByAppendingString("/insta.igo")
完整代码
var docController = UIDocumentInteractionController()
let instagramURL = NSURL(string: "instagram://app")
if(UIApplication.sharedApplication().canOpenURL(instagramURL!)) {
var imagePost = cropped
let fullPath = documentsDirectory().stringByAppendingString("/insta.igo")
var imageData = UIImagePNGRepresentation(imagePost!)!.writeToFile(fullPath, atomically: true)
let rect = CGRectMake(0, 0, 0, 0)
self.docController.UTI = "com.instagram.exclusivegram"
let igImageHookFile = NSURL(string: "file://\(fullPath)")
self.docController = UIDocumentInteractionController(URL: igImageHookFile!)
self.docController.presentOpenInMenuFromRect(rect, inView: self.view, animated: true)
}
func documentsDirectory() -> String {
let documentsFolderPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
return documentsFolderPath
}
答案 1 :(得分:0)
Andy Shephard 提供的解决方案为我工作: https://stackoverflow.com/a/32616355/1500708