Instagram 在 iOS 9 上的分享无法正常工作。

4

这在iOS 8上运行良好,但在iOS 9上,UIDocumentInteractionController没有出现“复制到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
}
2个回答

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

附注:var docController = UIDocumentInteractionController() 应该是类/VC的全局变量,不要将其放在 func 内。@noobsmcgoobs 试试看。 - Dan
1
@John,我无法感谢你的足够,你的评论应该成为一个独立的答案,我会点赞的。 - xytor

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接