首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Instagram分享在iOS 9上不起作用

Instagram分享在iOS 9上不起作用
EN

Stack Overflow用户
提问于 2015-09-25 07:38:18
回答 2查看 1.9K关注 0票数 4

这在iOS 8上运行得很好,但在iOS 9上,UIDocumentInteractionController确实出现了复制到Instagram的选项。按下它只会关闭控制器。

任何反馈都将不胜感激。

谢谢,

代码语言:javascript
复制
    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
}
EN

回答 2

Stack Overflow用户

发布于 2015-09-25 21:43:53

在声明"insta.igo“时,iOS9读取它的方式现在需要有"/”

代码语言:javascript
复制
let fullPath = documentsDirectory().stringByAppendingString("/insta.igo")

完整代码

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2015-09-25 16:20:06

这个由Andy Shephard提供的解决方案为我工作:https://stackoverflow.com/a/32616355/1500708

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32772609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档