iOS 14.2 版本,我无法像https://developers.facebook.com/docs/instagram/sharing-to-feed/中描述的那样分享图片。
但我可以从此菜单中正确地向其它应用程序分享相同的图片(例如 Telegram)。
代码:
func shareToInstagramFeed() {
let instagramURL = NSURL(string: "instagram://")
if UIApplication.shared.canOpenURL(instagramURL! as URL) {
let jpgPath = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.ig")
do {
try selectedImage.image?.jpegData(compressionQuality: 1)?.write(to: URL(fileURLWithPath: jpgPath), options: .atomic)
} catch {
print(error)
}
let rect = CGRect.zero
documentInteractionController = UIDocumentInteractionController(url: URL(fileURLWithPath: jpgPath))
documentInteractionController.delegate = self
documentInteractionController.uti = "com.instagram.photo"
documentInteractionController.presentOpenInMenu(from: rect, in: view, animated: true)
}
}