【发布时间】:2016-09-26 16:21:38
【问题描述】:
我正在使用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 ")
}
}
【问题讨论】:
-
它是怎么失败的?你有错误吗?它会默默地失败吗?
-
嗨 @NicolasMiari,当我尝试在 iOS 10 设备上将照片分享到 Instagram 时,它只是没有响应。是的,它默默地失败了,之后应用程序仍在工作。
标签: swift ios9 instagram ios10 url-scheme