首页 > 解决方案 > 绕过 instagram 菜单在 instagram 上共享 (Swift)

问题描述

我正在开发一个应用程序,我可以在其中分享到 instagram,但我想直接分享到 instagram 故事。

目前,当我尝试分享图片时,它正在打开 Instagram 故事菜单,然后我必须再次点击才能分享。

有没有办法绕过这个部分。

代码:

private let instagramStoriesURL = URL(string: "instagram-stories://share")

   public func postToInstagramStories(image: UIImage, backgroundTopColorHex: String, backgroundBottomColorHex: String, deepLink: String) {

        DispatchQueue.main.async {

                guard let urlScheme = self.instagramStoriesURL else {
                    self.delegate?.error(message: "URL not valid")
                    return
                }

                let pasteboardItems = ["com.instagram.sharedSticker.stickerImage": image,
                                       "com.instagram.sharedSticker.backgroundTopColor" : backgroundTopColorHex,
                                       "com.instagram.sharedSticker.backgroundBottomColor" : backgroundBottomColorHex,
                                       "com.instagram.sharedSticker.contentURL": deepLink] as [String : Any]

                if #available(iOS 10.0, *) {
                    let pasteboardOptions = [UIPasteboard.OptionsKey.expirationDate : NSDate().addingTimeInterval(60 * 5)]
                    UIPasteboard.general.setItems([pasteboardItems], options: pasteboardOptions)

                } else {
                    UIPasteboard.general.items = [pasteboardItems]
                }
                if #available(iOS 10.0, *) {
                    UIApplication.shared.open(urlScheme, options: [:], completionHandler: { (success) in
                        self.delegate?.success()
                    })
                } else {
                    UIApplication.shared.openURL(urlScheme)
                    self.delegate?.success()
                }
        }
    }

标签: iosswiftinstagramshare

解决方案


推荐阅读