I'm posting an Instagram story from my app and it works perfectly. But when I added a UIPasteboard string value where I store my URL, it's being cleared when I paste it in instagram link. What I notice is Instagram is clearing the paste board items when launched. Is there any way to keep the paste board items in Instagram? Here's my code snippet:
let urlScheme = URL(string:"instagram-stories://share")!
if UIApplication.shared.canOpenURL(urlScheme) {
UIPasteboard.general.string = Global.hostURL // THIS GETS CLEARED
let pasteBoardItems:Array<[String:Any]> = [
["com.instagram.sharedSticker.backgroundImage" : background.pngData()!]
]
let expirationDate = Date().addingTimeInterval(60 * 5)
let pasteBoardOptions = [UIPasteboard.OptionsKey.expirationDate: expirationDate]
UIPasteboard.general.setItems(pasteBoardItems, options: pasteBoardOptions)
UIApplication.shared.open(urlScheme)
}
Alternative solution is after
UIApplication.shared.open(shareURL, options: [:])Run
UIPasteboard.general.string = url.absoluteStringin the app delegate'sapplicationDidEnterBackgroundOr in SwiftUI's new lifecycle