Nut*_*ing 6 ios instagram swift instagram-api
我一直在尝试为我们的应用程序创建共享体验,其中Instagram启动时提供了以下两个选项:
Facebook有一个非常精简的文档。我使用UIDocumentInteractionController尝试了所有可能的排列。我尝试使用作为uti
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)
}
}
Run Code Online (Sandbox Code Playgroud)
进入上图所示屏幕的唯一方法是首先将视频保存在库中,然后使用instagram://library
传递资产的未记录挂钩localIdentifier
。不要忘记instagram
在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)
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这个 :-
我目前正在通过以下方式共享我上次保存的视频:
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)!)
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1296 次 |
最近记录: |