问题描述
我一直在尝试为我们的应用程序创建共享体验,Instagram启动后会提供以下两种选择:
I've been trying to create a sharing experience for our app where Instagram launches giving these two options:
Facebook有一个漂亮的精简文档.我使用UIDocumentInteractionController尝试了所有可能的排列.我尝试使用扩展名为ig
的uti
com.instagram.photo
和com.instagram.video
,但是我一直在获取标准的共享弹出窗口,而不是直接启动Instagram.在com.instagram.exclusivegram
和igo
之间也进行了尝试,但这似乎应该会触发标准弹出窗口.
Facebook has a pretty lean documentation about it. I tried all the possible permutations using the UIDocumentInteractionController. I tried using as uti
com.instagram.photo
and com.instagram.video
with the ig
extension but I keep getting the standard sharing popover instead of launching Instagram directly. Tried also com.instagram.exclusivegram
with igo
but that seems to be supposed to trigger the standard popover anyway.
最新代码:
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)
}
}
推荐答案
进入上述屏幕的唯一方法是先将视频保存在库中,然后使用未记录的挂钩instagram://library
传递资产.不要忘记在info.plist
中添加instagram
查询方案.
The only way to get to the screen illustrated above is to save first the video in the library and then use the undocumented hook instagram://library
passing the asset localIdentifier
. Don't forget to add instagram
query scheme in the info.plist
.
if UIApplication.shared.canOpenURL("instagram://app") { // has Instagram
let url = URL(string: "instagram://library?LocalIdentifier=" + videoLocalIdentifier)
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler:nil)
}
}
这篇关于从iOS将视频分享到Instagram提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!