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.
To implement custom sharing of an image to Instagram without presenting a share sheet, you can use the Instagram URL scheme in your code. Here are the steps to achieve this:
Replace "yourImageURL" with the URL of the image you want to share on Instagram.
This will open the Instagram app and allow the user to share the image directly without presenting a share sheet.
Note: Instagram's URL scheme and API are subject to change without notice, so it's a good idea to check the Instagram Developer Documentation for the latest information.