Instagram sharing not working in iOS 9

This works fine on iOS 8, but on iOS 9 a UIDocumentInteractionController appears with the Copy to Instagram option. Clicking on it just rejects the controller.

Any feedback would be appreciated.

Thanks,

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

    if(UIApplication.sharedApplication().canOpenURL(instagramURL!)) {
        var imagePost = cropped
        let fullPath = documentsDirectory().stringByAppendingString("insta.igo")
        var imageData = UIImagePNGRepresentation(imagePost!)!.writeToFile(fullPath, atomically: true)
        let rect = CGRectMake(0, 0, 0, 0)
        self.docController.UTI = "com.instagram.exclusivegram"
        let igImageHookFile = NSURL(string: "file://\(fullPath)")
        self.docController = UIDocumentInteractionController(URL: igImageHookFile!)

        self.docController.presentOpenInMenuFromRect(rect, inView: self.view, animated: true)

    }

    func documentsDirectory() -> String {
    let documentsFolderPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
    return documentsFolderPath
}
+4
source share
3 answers

I figured this out and left it here if anyone else has a problem.

IOS9 reading method when declaring "insta.igo" should now have a "/"

    let fullPath = documentsDirectory().stringByAppendingString("/insta.igo")

Full code

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

if(UIApplication.sharedApplication().canOpenURL(instagramURL!)) {
    var imagePost = cropped
    let fullPath = documentsDirectory().stringByAppendingString("/insta.igo")
    var imageData = UIImagePNGRepresentation(imagePost!)!.writeToFile(fullPath, atomically: true)
    let rect = CGRectMake(0, 0, 0, 0)
    self.docController.UTI = "com.instagram.exclusivegram"
    let igImageHookFile = NSURL(string: "file://\(fullPath)")
    self.docController = UIDocumentInteractionController(URL: igImageHookFile!)

    self.docController.presentOpenInMenuFromRect(rect, inView: self.view, animated: true)

}

func documentsDirectory() -> String {
let documentsFolderPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
return documentsFolderPath

}

+3
source

the URL scheme has changed to iOS 9, you need to add the LSApplicationQueriesSchemes key to plist, otherwise the call toOpenURL: does not work and always returns false, even if you already have the application installed.

plist,

<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
0

This solution provided by Andy Shephard worked for me: fooobar.com/questions/713006 / ...

0
source

Source: https://habr.com/ru/post/1608907/


All Articles