Is there a way to post a video or photo directly to the Instagram Stories of the user's Instagram account? For a normal photo share on Instagram, you can use the URL Scheme and open the Editor directly. Is there a way for Stories, too?
Thanks!
Swift 4.2 version of knshn's answer:
func shareBackgroundImage() {
let image = UIImage(imageLiteralResourceName: "backgroundImage")
if let pngImage = image.pngData() {
backgroundImage(pngImage, attributionURL: "http://your-deep-link-url")
}
}
func backgroundImage(_ backgroundImage: Data, attributionURL: String) {
// Verify app can open custom URL scheme, open if able
guard let urlScheme = URL(string: "instagram-stories://share"),
UIApplication.shared.canOpenURL(urlScheme) else {
// Handle older app versions or app not installed case
return
}
let pasteboardItems = [["com.instagram.sharedSticker.backgroundImage": backgroundImage,
"com.instagram.sharedSticker.contentURL": attributionURL]]
let pasteboardOptions: [UIPasteboard.OptionsKey: Any] = [.expirationDate: Date().addingTimeInterval(60 * 5)]
// This call is iOS 10+, can use 'setItems' depending on what versions you support
UIPasteboard.general.setItems(pasteboardItems, options: pasteboardOptions)
UIApplication.shared.open(urlScheme)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With