Eya*_*yal 8 ios uidocumentinteraction instagram uiactivityviewcontroller
是否可以在Instagram上分享视频而不将其保存到用户的相机胶卷?
这是我到目前为止所尝试的:
let instagramURL = URL(string: "instagram://app")!
if (UIApplication.shared.canOpenURL(instagramURL)) {
self.documentController = UIDocumentInteractionController(url: videoURL)
self.documentController.delegate = self
self.documentController.uti = "com.instagram.exlusivegram"
self.documentController.presentOpenInMenu(from: self.view.frame, in: self.view, animated: true)
} else {
print(" Instagram isn't installed ")
}
Run Code Online (Sandbox Code Playgroud)
videoURL是我保存在Documents文件夹中的视频的URL.
如果我Instagram.igo在最后保存URL ,那么当我选择Instagram分享它时会打开如下:

如果我在最后用.mov保存视频,那么Instagram分享似乎会打开一张照片(如视频缩略图),而不是视频.
你究竟做错了什么很难确定,但我会尽力解决你可能出错的地方.
首先确保videoURL是在本地定义的.当我写一篇应用程序发布到Instagram时,我首先用文件管理器定义了路径,如:
let tempDirectory = FileManager().temporaryDirectory
var postingPath = tempDirectory.appendingPathComponent("postingVideo")
postingPath = postingPath.appendingPathExtension("igo")
Run Code Online (Sandbox Code Playgroud)
然后我将电影写入此目录,几乎与您的代码相同.请考虑您需要创建igo文件夹,然后将影片保存到此文件夹中.如果您尝试引用电影所在的文件夹,您的应用程序将无法读取电影文件,也不会发布任何内容.如果它是照片库中的电影文件,请使用AVExportSession并将其导出到postsPath.
self.instagramController = UIDocumentInteractionController.init(url: postingPath)
self.instagramController.uti = "com.instagram.exclusivegram"
self.instagramController.delegate = self
self.instagramController.presentOpenInMenu(from:
self.navigationItem.rightBarButtonItem!, animated: true)
Run Code Online (Sandbox Code Playgroud)
但是,您需要使您的类发布到Instagram遵守UIDocumentInteractionControllerDelegate,否则您需要强制转换为self.你还需要包括社交.我不认为你在这篇文章的第二部分做了任何错误,因为你会得到xcode错误和警告.
我希望第一部分可以进一步帮助你,因为我不认为第二部分给你带来了问题.
| 归档时间: |
|
| 查看次数: |
2500 次 |
| 最近记录: |