我正在使用这个课程
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")
}
}
}
以及我如何使用它:
.........
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)
}
当我的应用程序将图片发送到Instagram并且我点击了Feed时,Instagram应用程序正在打开图库,它不共享我发送的图片。
这个问题本周发生了新的Instagram ios更新