iOS10 swift 2.2 share on Instagram openURL&canOpenURL change



我正在使用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 ")
        }
    }

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

最新更新