10

after new Instagram IOS update i am not able to share images from my app to instagram , when i attempt to share it its goes there to instagram but when i click Feed instagram is opening the gallery not my photo to share .

i am using this class

import UIKit
import Foundation

class InstagramManager: NSObject, UIDocumentInteractionControllerDelegate {

    private let kInstagramURL = "instagram://app"
    private let kUTI = "com.instagram.exclusivegram"
    private let kfileNameExtension = "instagram.igo"
    private let kAlertViewTitle = "Error"
    private let kAlertViewMessage = "Please install the Instagram application"

    var documentInteractionController = UIDocumentInteractionController()

    // singleton manager
    class var sharedManager: InstagramManager {
        struct Singleton {
            static let instance = InstagramManager()
        }
        return Singleton.instance
    }

    func postImageToInstagramWithCaption(imageInstagram: UIImage, instagramCaption: String, view: UIView) {
        // called to post image with caption to the instagram application

        let instagramURL = NSURL(string: kInstagramURL)

        if UIApplication.shared.canOpenURL(instagramURL! as URL) {

            let jpgPath = (NSTemporaryDirectory() as NSString).appendingPathComponent(kfileNameExtension)

            do {
                try UIImageJPEGRepresentation(imageInstagram, 1.0)?.write(to: URL(fileURLWithPath: jpgPath), options: .atomic)

            } catch {

                print(error)
            }

            let rect = CGRect(x: 0, y: 0, width: 612, height: 612)
            let fileURL = NSURL.fileURL(withPath: jpgPath)
            documentInteractionController.url = fileURL
            documentInteractionController.delegate = self
            documentInteractionController.uti = kUTI

            // adding caption for the image
            documentInteractionController.annotation = ["InstagramCaption": instagramCaption]
            documentInteractionController.presentOpenInMenu(from: rect, in: view, animated: true)
        } else {

            /// display some message about how it didn't work
            /// Like: UIAlertController(title: kAlertViewTitle, message: kAlertViewMessage, preferredStyle: .alert)
             MUZAlert().error(text: "Please login to Instagram in your Device")
        }
    }
} 

and here how i am using it :

.........

                        UIImage(named: "apple_download")?.draw(in: CGRect( x: 70 ,
                                                                           y: frameHeight! - 100,
                                                                           width: 220,
                                                                           height: 80), blendMode: .normal, alpha: 1)


                        UIImage(named: "play_download")?.draw(in: CGRect(  x: frameWidth! /  2 + 20  ,
                                                                           y: frameHeight! - 100,
                                                                           width: 220,
                                                                           height: 80), blendMode: .normal, alpha: 1)

                       if  let result = UIGraphicsGetImageFromCurrentImageContext()
                        {
                            UIGraphicsEndImageContext()
                            InstagramManager.sharedManager.postImageToInstagramWithCaption(imageInstagram: result,
                                                                                           instagramCaption: "",
                                                                                           view: self.view)
                        }

When my app send the picture to Instagram and i click on feed , Instagram application is opening the gallery its not sharing the picture i sent.

enter image description here

this issue happened this week with new Instagram ios update

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Kodr.F
  • 13,932
  • 13
  • 46
  • 91

0 Answers0