Sharing Photo and Copying String to Instagram Stories

435 Views Asked by At

I have an app that allows a user to share to an image to IG stories. My problem is, I can't seem to simultaneously copy a url string from which a user can then paste as an IG Link sticker.

I couldn't find any existing solution and any thoughts would be appreciated.

I tried setting the pasteboard string to the urlString in the completion handler for UIApplication.shared.open to no avail.

My code:

func share(_ sender: Any) {
 
if let urlScheme = URL(string: "instagram-stories://share"), UIApplication.shared.canOpenURL(urlScheme), let pngImage = backgroundImage.pngData() {
    
    UIPasteboard.general.string = "urlString"
    
    let pasteboardItems = [["com.instagram.sharedSticker.backgroundImage": pngImage]]
    let pasteboardOptions: [UIPasteboard.OptionsKey: Any] = [.expirationDate: Date().addingTimeInterval(60 * 5)]
    
    UIPasteboard.general.setItems(pasteboardItems, options: pasteboardOptions)
    UIApplication.shared.open(urlScheme)
}
0

There are 0 best solutions below