iOS10 swift 2.2在Instagram上分享openURL& canOpenURL改变

时间:2016-09-26 16:21:38

标签: swift ios9 instagram ios10 url-scheme

我正在使用swift 2.2分享照片到Instagram的功能,它适用于iOS9但是iOS10失败了,iOS9和iOS10之间有什么区别吗? 以下是我在iOS9上实现它的方法,感谢任何建议。

class viewController: UIViewController, UIDocumentInteractionControllerDelegate {

var yourImage: UIImage?
var documentController: UIDocumentInteractionController!

func shareToInstagram() {

 let instagramURL = NSURL(string: "instagram://app")

        if (UIApplication.sharedApplication().canOpenURL(instagramURL!)) {

            let imageData = UIImageJPEGRepresentation(yourImage!, 100)

            let captionString = "caption"

       let writePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("instagram.igo")
       if imageData?.writeToFile(writePath, atomically: true) == false {

                return

            } else {
 let fileURL = NSURL(fileURLWithPath: writePath)

                self.documentController = UIDocumentInteractionController(URL: fileURL)

                self.documentController.delegate = self

                self.documentController.UTI = "com.instagram.exlusivegram"

                self.documentController.annotation = NSDictionary(object: captionString, forKey: "InstagramCaption")
                      self.documentController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true)

            }

        } else {
            print(" Instagram isn't installed ")
        }
    }

1 个答案:

答案 0 :(得分:0)

问题解决了,只需更新到xcode8并使用swift2.3。