首页 > 解决方案 > 从 iOS 将视频分享到 Instagram 源

问题描述

我一直在尝试为我们的应用程序创建共享体验,在 Instagram 启动时提供以下两个选项:

在此处输入图像描述

Facebook 有关于它的非常精简的文档。我使用 UIDocumentInteractionController 尝试了所有可能的排列。我尝试使用 asuti com.instagram.photo和扩展com.instagram.videoig但我一直得到标准的共享弹出窗口,而不是直接启动 Instagram。也尝试过com.instagram.exclusivegramigo但这似乎应该触发标准弹出框。

最新代码:

func shareVideo(_ filePath: String) {
  let url = URL(fileURLWithPath: filePath)
  if(hasInstagram()){
    let newURL = url.deletingPathExtension().appendingPathExtension("ig")
    do {
      try FileManager.default.moveItem(at: url, to: newURL)
    } catch { print(error) }

    let dic = UIDocumentInteractionController(url: newURL)
    dic.uti = "com.instagram.photo"
    dic.presentOpenInMenu(from: self.view.frame, in: self.view, animated: true)
  }
}

标签: iosswiftinstagraminstagram-api

解决方案


试试这个 :-

我目前正在通过以下方式分享我上次保存的视频:-

    let fetchOptions = PHFetchOptions()
    fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
    let fetchResult = PHAsset.fetchAssets(with: .video, options: fetchOptions)
    if let lastAsset = fetchResult.firstObject {
        let localIdentifier = lastAsset.localIdentifier
        let u = "instagram://library?LocalIdentifier=" + localIdentifier
        let url = NSURL(string: u)!
        if UIApplication.shared.canOpenURL(url as URL) {
            UIApplication.shared.open(URL(string: u)!, options: [:], completionHandler: nil)
        } else {

            let urlStr = "https://itunes.apple.com/in/app/instagram/id389801252?mt=8"
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)

            } else {
                UIApplication.shared.openURL(URL(string: urlStr)!)
            }
        }

    }

推荐阅读