after a new Instagram iOS update, I can’t share images with my instagram app, when I try to share it, it goes there to launch instagram, but when I click the Feed button, we open the gallery, not my photo.
I use 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()
class var sharedManager: InstagramManager {
struct Singleton {
static let instance = InstagramManager()
}
return Singleton.instance
}
func postImageToInstagramWithCaption(imageInstagram: UIImage, instagramCaption: String, view: UIView) {
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
documentInteractionController.annotation = ["InstagramCaption": instagramCaption]
documentInteractionController.presentOpenInMenu(from: rect, in: view, animated: true)
} else {
MUZAlert().error(text: "Please login to Instagram in your Device")
}
}
}
, and here is how I use 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 application sends an image to Instagram, and I click on the channel, the Instagram application opens the gallery, not the image that I sent.
this problem happened this week with the new Instagram ios update