iOS10 swift 2.2 分享到Instagram openURL& canOpenURL change
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.
我正在使用 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.