【问题标题】:iOS 13 Instagram-only photo sharing does not workiOS 13 仅限 Instagram 的照片共享不起作用
【发布时间】:2019-11-08 12:47:39
【问题描述】:

在 iOS 12.4 之前,将照片共享到 Instagram 提要(遵循 documentation)可以正常工作,但从 iOS 13 开始,它不再工作了。

在当前实现中 - UIDocumentInteractionController 的 UTI 设置为 "com.instagram.exclusivegram",文件扩展名设置为 .igo - 根本看不到 Instagram 共享选项。当我将文件扩展名更改为 .ig 时,我可以在建议中看到 Instagram 共享选项。这种分享到 feed 的方式是可行的,但这不是预期的仅限 Instagram 的解决方案。

将 UTI 设置为 "com.instagram.photo" 不会改变任何内容。

预期的行为是当我点击“分享”按钮时看到下面可见的视图,无需额外步骤。这可能是 Instagram 的错误,还是有其他方法可以为 iOS 13 实现它?

【问题讨论】:

  • FWIW,我正在解决完全相同的问题。我在运行 iOS 11、12 和 13 的设备上安装了 119.0 版本的 Instagram,而问题仅出现在运行 iOS 13 的设备上。猜猜这意味着它在 iOS 13 上已被破坏,而不是具体到 Instagram 应用程序。

标签: swift instagram ios13 xcode11


【解决方案1】:

您应该将您的图片添加到照片库,然后将图片直接分享到 Instagram

首先不要忘记将 NSPhotoLibraryAddUsageDescription 和 instagram 方案添加到您的 info.plist:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) wants to save pictures to your library</string>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>instagram</string>
</array>

适用于 12.413 iOS

import UIKit
import Photos

class TestViewController: UIViewController, UIDocumentInteractionControllerDelegate {

override func viewDidLoad() {
    super.viewDidLoad()
    postImageToInstagram(UIImage(named: "bigImage")!)
}

func postImageToInstagram(_ image: UIImage) {
    // Check if we have instagarm app
    if UIApplication.shared.canOpenURL(URL(string: "instagram://app")!) {
        // Requesting authorization to photo library in order to save image there
        PHPhotoLibrary.requestAuthorization { status in
            if status == .authorized {
                UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
            } else { print("wrong status \(status)") }
        }
    } else { print("Please install the Instagram application") }
}

@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
    if let error = error {
        print(error)
        return
    }
    let fetchOptions = PHFetchOptions()
    // add sorting to take correct element from fetchResult
    fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
    fetchOptions.fetchLimit = 1
    // taking our image local Identifier in photo library to share it
    let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions)
    if let lastAsset = fetchResult.firstObject {
        let url = URL(string: "instagram://library?LocalIdentifier=\(lastAsset.localIdentifier)")!
        if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) }
        else { print("Please install the Instagram application") }
    }
}
}

结果

【讨论】:

  • 救了我。官方 instagram 文档指出应该使用带有“ig”或“igo”扩展名的文档交互 API 具有误导性(“ig”= 显示所有应用程序,“igo”= 未显示 instagram 应用程序),这个工作完美无缺(在ios 13.7)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多