在Xcode 7上通过swift分享到Instagram?

时间:2015-10-02 19:14:35

标签: ios xcode swift instagram xcode7

所以在堆栈溢出和在线的其他几个地方我看到这个代码:

func postImage2() {
            var instagramURL = NSURL(string: "instagram://app")

            if(UIApplication.sharedApplication().canOpenURL(instagramURL!)) {
                var imagePost = image
                var fullPath = documentsDirectory().stringByAppendingPathComponent("insta.igo")
                var imageData = UIImagePNGRepresentation(imagePost).writeToFile(fullPath, atomically: true)
                var rect = CGRectMake(0, 0, 0, 0)
                self.docController.UTI = "com.instagram.exclusivegram"
                var igImageHookFile = NSURL(string: "file://\(fullPath)")
                self.docController = UIDocumentInteractionController(URL: igImageHookFile!)
                self.docController.annotation = ["InstagramCaption":"Text"]
                self.docController.presentOpenInMenuFromRect(rect, inView: self.view, animated: true)

            } else {
                print("no instagram found")
            }

        }

然而,这引起了一个抱怨:​​stringByAppendingPathComponent不可用。而是在NSURL上使用URLByAppendingPathComponent。我听说这是苹果试图让人们从基于字符串的路径转移到网址的新举措。

在任何情况下,我如何更新此代码以使其适用于URLByAppendingPathComponent?

0 个答案:

没有答案