【问题标题】:Instagram sharing not working on iOS 9Instagram 分享无法在 iOS 9 上运行
【发布时间】:2015-09-24 23:38:17
【问题描述】:

这在 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
}

【问题讨论】:

    标签: hook instagram ios9


    【解决方案1】:

    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
    

    【讨论】:

    • 旁注:对于类/VC,var docController = UIDocumentInteractionController() 应该是全局的,不要把它放在func 中。试试@noobsmcgoobs。
    • @John 我非常感谢你,你的评论本身应该是一个答案,我会支持它。
    【解决方案2】:

    Andy Shephard 提供的这个解决方案对我有用: https://stackoverflow.com/a/32616355/1500708

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多