【问题标题】:ios iphone hooks open instagram directly without showing UIDocumentInteractionControllerios iphone hooks直接打开instagram而不显示UIDocumentInteractionController
【发布时间】:2013-05-20 10:45:22
【问题描述】:

我正在我的应用程序中集成通过 instagram 共享图像。我读过他们的documentation

看来我需要使用 iOS UIDocumentInteractionController 来允许这样做(我知道它允许访问我应用程序沙箱中的文件)。

深入挖掘,我发现了这个library,这让事情变得非常简单。

我遇到的问题是它显示了操作表(它只有一个按钮 - Instagram...)我如何使用 instagram 钩子和 UIDocumentInteractionController 而不显示操作表。我遇到了这个question,它几乎是一样的,但它已经过时了,没有答案。

【问题讨论】:

    标签: ios instagram uidocumentinteraction uidocument


    【解决方案1】:

    我使用了一个非常简单的分享打开 Instagram 流程。

    • 我将图像本地保存到照片中
    • 然后我使用以下 URL 打开 Instagram:instagram://library?AssetPath=assets-library

    这会将 Instagram 直接打开到照片库。由于照片是在片刻前保存的,因此新照片作为图库中的第一张照片可见。

    【讨论】:

    • 男人.. 太棒了!我认为这是一种打开照片库而不是相机的方法,但这甚至更适合共享单张照片。好吧..如果你有一个打开照片库的 URI,我也会接受它^^
    【解决方案2】:

    我自己搜索过这个,我认为在不显示操作表的情况下使用 UIDocumentInteractionController 是不可能的,在不使用 UIDocumentInteractionController 的情况下似乎也不可能与 instagram 共享图像。

    这导致了不可避免的行动表。

    我理解他们为什么这样设计它(您不会在不知不觉中以用户身份离开应用程序),但在许多情况下它会导致烦人的 UI 设计。

    【讨论】:

    • 检查镜头应用。他们在没有 UIDocumentInteractionController 的情况下这样做。我想知道如何..
    • 应用程序“10”在没有操作表的情况下共享。这就是让我搜索这个主题的原因。
    【解决方案3】:

    Instagram documentation 中似乎没有提到了这种方法。但是,我刚刚确认 @sabiland's 答案在 Swift 4.2 iOS 12 中仍然有效。这是一些示例代码:

    func postImageToInstagram(image: UIImage) {
        UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(image:didFinishSavingWithError:contextInfo:)), nil)
    }
    
    @objc func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) {
        if let err = error {
            print(err)
        }
    
        let urlString = "instagram://library?AssetPath=assets-library"
    
        let url = URL(string: urlString)!
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        } else {
            let alertController = UIAlertController(title: "Error", message: "Instagram is not installed", preferredStyle: .alert)
            alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
            self.present(alertController, animated: true, completion: nil)
        }
    }
    

    Original code source

    您还必须确保您 info.plist 具有 instagram 查询方案。

    为了让您的应用使用 Instagram 的自定义 URL 方案,您必须通过将 instagram:// 添加到应用 Info.plist 中的 LSApplicationQueriesSchemes 键来将该方案列入白名单。

    Source

    【讨论】:

    • 在通过共享表使用 Instagram 挂钩的旧方法在 iOS 13 中停止正常工作后,刚刚将我的应用程序切换为使用此方法。这也是一种更清洁、更好的方法!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多