我在swift中有一个照片编辑应用程序,需要选择直接共享到Instagram。
Instagram在这里提供了对iphone钩子的参考,但实施证明是困难的
理想情况下,页面类有一个按钮,应该发送保存为pic.igo的图片,(。。仅保证instagram)并将用户直接带到Instagram上的帖子页面,已经选择了“pic.igo”
下面是钩子给你的东西,我似乎无法找到任何现代用例。整页在下面的链接中
NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
那么我该怎么把它放到这个函数中呢
@IBAction func Button(_ sender: Any) {
}
Iphone挂钩doc
https://www.instagram.com/developer/mobile-sharing/iphone-hooks/
注意 - 检查应用程序是否已经安装会有所帮助,但我真的只需要找到一种方法来使这个功能起作用,我可以在其他方面摸索
如果你只是在寻找他们提供的ObjC代码的Swift翻译,那就是结果:
@IBAction func Button(_ sender: Any) {
if let instagramURL = URL(string: "instagram://location?id=1"),
UIApplication.shared.canOpenURL(instagramURL) {
UIApplication.shared.open(instagramURL)
}
}
如果您在从ObjC转换代码时遇到问题,可以试试一些在线转换器,这里有几个选项:
但以上不是为了分享到Instagram,如果你想分享,那就是你需要做的:
guard let instagramURL = URL(string: "instagram://app"),
UIApplication.shared.canOpenURL(instagramURL) else {
print("Instagram app is not installed")
return
}
let yourIgoFile = Bundle.main.url(forResource: "test", withExtension: "igo")!
let documentController = UIDocumentInteractionController(url: yourIgoFile)
documentController.uti = "com.instagram.exclusivegram"
documentController.presentOpenInMenu(from: view.bounds, in: view, animated: true)