Instagram的NSURL实现与swift

问题描述 投票:0回答:1

我在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/

注意 - 检查应用程序是否已经安装会有所帮助,但我真的只需要找到一种方法来使这个功能起作用,我可以在其他方面摸索

  • 我认为文档中的“media?id = MEDIA_ID”替换了给定片段中的位置部分,但是我如何将视图中的图片分配给MEDIA_ID
  • 剪切和粘贴让我有80个错误,无法进行视觉恢复
swift instagram photo url-scheme custom-url
1个回答
0
投票

如果你只是在寻找他们提供的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)
© www.soinside.com 2019 - 2024. All rights reserved.