Last active
February 6, 2020 20:29
-
-
Save giovani-pereira-ifood/2484bf04862d94985a46dc5c47cefd94 to your computer and use it in GitHub Desktop.
create instagram sharing content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createInstagramStoriesSharing(for image: UIImage) -> URL? { | |
guard let url = URL(string: "instagram-stories://share") else { return nil } | |
// Add image to Pasteboard | |
let imageData = image.pngData() | |
let pasteboardItems: [[String: Any]] = [["com.instagram.sharedSticker.backgroundImage": image]] | |
// Update with new pasteboard items | |
UIPasteboard.general.setItems(pasteboardItems, options: [UIPasteboard.OptionsKey.expirationDate: Date().addingTimeInterval(60)]) | |
return url | |
} | |
guard let sharingURL = createInstagramStoriesSharing(for: UIImage(named: "sharing")), | |
UIApplication.shared.canOpenURL(sharingURL) else { | |
// Handle instagram sharing error | |
return | |
} | |
// Open Instagram | |
UIApplication.shared.open(sharingURL, options: [:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment