【问题标题】:How to directly share an image to instagram?如何直接分享图片到instagram?
【发布时间】:2019-09-20 01:35:15
【问题描述】:

我已经看到了如何分享到 instagram 的答案。问题是我无法直接分享到 insta。目前,当我运行此代码时,我会从底部弹出一个要分享的内容,当我点击时看到 复制到 Instagram,然后它会打开 insta 并且我可以分享。但我想跳过这一步,就像我在其他应用程序中看到的那样。 我该怎么做?

我目前的代码:

                 let instagramURL = URL(string: "instagram://app")
                if UIApplication.shared.canOpenURL(instagramURL!) {
                    if let url = Auth.auth().currentUser?.photoURL {
                        let image = self.getImage(url: url)
                        let imageData = image.jpegData(compressionQuality: 1.0)//UIImage.jpegData(image)
                        let writePath = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.igo")
                        do {
                            try imageData!.write(to: URL(fileURLWithPath: writePath), options: .atomic)
                            //try imageData.write(to: URL(fileURLWithPath: writePath), options: .atomic)
                        } catch {
//                            print(error)
                        }

                        let fileURL = URL(fileURLWithPath: writePath)
                        self.documentController = UIDocumentInteractionController(url: fileURL)
                        self.documentController.delegate = self
                        self.documentController.uti = "com.instagram.exlusivegram"

                        if UIDevice.current.userInterfaceIdiom == .phone {
                            self.documentController.presentOpenInMenu(from: self.view.bounds, in: self.view, animated: true)
                        }
//                        else {
//                            self.documentController.presentOpenInMenu(from: self.IGBarButton, animated: true)
//                        }
                    } else {
                        let imageData = UIImage(named: "media")!.jpegData(compressionQuality: 1.0)//UIImage.jpegData(image)
                        let writePath = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.igo")
                        do {
                            try imageData!.write(to: URL(fileURLWithPath: writePath), options: .atomic)
                        } catch {
//                            print(error)
                        }

                        let fileURL = URL(fileURLWithPath: writePath)
                        self.documentController = UIDocumentInteractionController(url: fileURL)
                        self.documentController.delegate = self
                        self.documentController.uti = "com.instagram.exlusivegram"

                        if UIDevice.current.userInterfaceIdiom == .phone {
                            self.documentController.presentOpenInMenu(from: self.view.bounds, in: self.view, animated: true)
                        }
//                        else {
//                            self.documentController.presentOpenInMenu(from: self.IGBarButton, animated: true)
//                        }
                    }
                }

【问题讨论】:

  • 通过 Instagram 分享的官方方式是使用文档交互 API。这就是你正在做的事情。您将无法代表用户发布内容,或者至少在未经用户授予其共享工作流程许可的情况下发布。
  • @Derek 我不想为他们分享,我只想跳过你必须选择 insta 的步骤,用户已经选择了它,所以我想直接用图像打开它
  • 你试过this吗?
  • @SorushShahi 现在试试
  • @SorushShahi 工作!

标签: ios swift instagram


【解决方案1】:

我在这里找到了解决方案:IOS. Sharing image to Instagram without using a menu display

正如 Soroush Shahi 在 cmets 中所说的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    相关资源
    最近更新 更多