ios - 从 iOS 将视频分享到 Instagram 源
问题描述
我一直在尝试为我们的应用程序创建共享体验,在 Instagram 启动时提供以下两个选项:
Facebook 有关于它的非常精简的文档。我使用 UIDocumentInteractionController 尝试了所有可能的排列。我尝试使用 asuti
com.instagram.photo
和扩展com.instagram.video
,ig
但我一直得到标准的共享弹出窗口,而不是直接启动 Instagram。也尝试过com.instagram.exclusivegram
,igo
但这似乎应该触发标准弹出框。
最新代码:
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)
}
}
解决方案
试试这个 :-
我目前正在通过以下方式分享我上次保存的视频:-
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)!)
}
}
}
推荐阅读
- spring-boot - CorruptedTransactionLogException : 发现损坏的日志
- python - 如何在 QML 中使用 QtWebEngine
- node.js - 如何在 Foreach 中同步运行 Mongoose Find
- html - 按元素抓取网页
- ios - 如何在 Xcode 中正确设置 UIButtons(图像)的约束?
- c - 这个基于指针的代码的答案是什么,为什么?
- c# - Windows IoT 上的多线程导致线程关闭
- java - BroadcastReceiver 未在 Android 8.1+ 上捕获呼叫事件
- reactjs - 具有循环连接的层次树
- java - 如何在我的单元测试中使用 Mockito 或任何 Mocking 框架来模拟 Guice 注入?