I want to enable a feature in my iOS app to share image on Instagram directly. While the conventional way is to present a share sheet provided by Apple, I prefer to have an Instagram button that allows users to share image easily without opening the share sheet. I have found two URLs that can be used for this purpose: "instagram://share" for posts and "instagram-stories://share" for stories.
However, I have seen other apps that display a 'Share to Instagram' sheet with three default options as shown in figure. I am interested in implementing this feature in my app.
My code is given below:
func shareOnInstagram(image: UIImage) {
if let url = URL(string: "instagram://share") {
if UIApplication.shared.canOpenURL(url) {
guard let imageData = image.jpegData(compressionQuality: 1.0) else { return }
let pasteboardItem : [String: Any] = ["com.instagram.sharedSticker.stickerImage": imageData]
]
let pasteboardOptions = [
UIPasteboard.OptionsKey.expirationDate : Date().addingTimeInterval(300)
]
UIPasteboard.general.setItems([pasteboardItem], options: pasteboardOptions)
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
else {
print("User doesn't have IG on their device.")
}
}
}
I have been trying to find a way to integrate this sheet, but unfortunately, not been successful yet. Therefore, I am seeking guidance on how to integrate this sheet into my app to allow for direct sharing to Instagram.