我正在使用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 ")
}
}
答案 0 :(得分:0)
问题解决了,只需更新到xcode8并使用swift2.3。