swift - Instagram NSURL 使用 swift 实现

标签 swift instagram photo url-scheme custom-url

我有一个 swift 中的照片编辑应用程序,它需要直接分享到 Instagram 的选项。

Instagram 在这里提供了 iphone hooks 的引用,但事实证明实现起来很困难

理想情况下,pages 类有一个按钮,可以发送保存为 pic.igo 的图片(.igo 仅确保 instagram),并将用户直接带到 Instagram 上的帖子页面,并且已选择“pic.igo”

这就是钩子(Hook)给你的,我似乎找不到任何现代用例。完整页面位于下面的链接中

NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [[UIApplication sharedApplication] openURL:instagramURL];
}

那么我如何将其放入这个函数中

@IBAction func Button(_ sender: Any) {


}

Iphone Hook 文档

https://www.instagram.com/developer/mobile-sharing/iphone-hooks/

注释 - 检查应用程序是否已安装会有所帮助,但我真的只需要找到一种方法来使此功能正常工作,我可以摸索其余的事情

  • 文档中的“media?id=MEDIA_ID” 我假设替换了给定代码片段中的位置部分,但是如何将 View 中的图片分配给 MEDIA_ID

  • 剪切和粘贴给我留下了大约 80 个错误,并且无法恢复视力

最佳答案

如果您只是寻找他们提供的 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)

关于swift - Instagram NSURL 使用 swift 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55602834/

相关文章:

macos - 检查文件是否是 Swift 的别名

Android 如何获取联系人照片的图像路径?

iphone - 在 iOS 中通过 Objective-C/Xcode 访问图片库

java - 使用 Android 拍摄单色照片(黑白)

ios - swift ios9 : Trying to start MapKit location updates without prompting for location authorization

ios - SpriteKit - 如何处理多种屏幕尺寸?

swift - 无缝 NSStatusItem 按钮突出显示自定义 NSView 覆盖

postgresql - Instragram 的 UUID 创建失败

ios - Instagram iOS Hook 与非方形图像

PHP 生成的图像不继承包含 div 的样式