ios iphone直接打开instagram,而不显示UIDocumentInteractionController

ios iphone直接打开instagram,而不显示UIDocumentInteractionController,ios,instagram,uidocumentinteraction,uidocument,Ios,Instagram,Uidocumentinteraction,Uidocument,我正在我的应用程序中通过instagram集成共享图像。我读过他们的书 似乎我需要使用iOS UIDocumentInteractionController来实现这一点(我知道它允许访问我应用程序沙箱中的文件) 深入挖掘,我发现了这一点,这使事情变得非常简单 我的问题是,它显示了操作表(只有一个按钮-Instagram…),我如何使用Instagram挂钩和UIDocumentInteractionController,而不显示操作表。我遇到了这个几乎是一样的,但它已经过时了,没有答案 我自己也

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

似乎我需要使用iOS UIDocumentInteractionController来实现这一点(我知道它允许访问我应用程序沙箱中的文件)

深入挖掘,我发现了这一点,这使事情变得非常简单


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

我自己也搜索过,我不认为不显示操作表就可以使用UIDocumentInteractionController,也不可能不使用UIDocumentInteractionController就与instagram共享图像

这导致不可避免的行动表


我理解他们为什么这样设计(你不会在不知不觉中把应用程序作为用户留下),但在许多情况下,这会导致令人讨厌的UI设计。

我使用一个非常简单的共享开放Instagram流

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

这将直接将Instagram打开到照片库中。因为照片是在几分钟前保存的,所以新照片作为库中的第一张照片可见。

看起来此方法是中没有提到的。不过,我刚刚确认,答案仍然适用于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)
    }
}

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

为了让您的应用程序使用Instagram的自定义URL方案,您必须将Instagram://添加到应用程序Info.plist中的LSApplicationQueriesSchemes密钥中,从而将该方案列入白名单


检查快照应用程序。他们在没有UIDocumentInteractionController的情况下完成。我想知道应用程序“10”如何在没有操作表的情况下共享。这就是我在这个话题上搜索的原因。。太棒了!我原以为这是一种打开照片库而不是相机的方法,但对于共享单张照片来说,这甚至更好。好。。如果你有一个URI来打开photolibrary,我也这么认为^^在iOS 13中,通过共享表使用Instagram钩子的旧方法停止正常工作后,我的应用程序切换到使用此方法。这也是一种更干净、更好的方法!