首页 > 解决方案 > 如何打开 Instagram 查询方案以分享到故事?

问题描述

当我尝试将图像分享到 Instagram 故事时,我收到以下错误: 不允许此应用查询方案 instagram-stories

虽然我将自定义 URL 方案instagram-stories添加到LSApplicationQueriesSchemes

我遵循了 Instagram 的文档:https ://developers.facebook.com/docs/instagram/sharing-to-stories/#ios-developers ,我的代码如下:

private func shareToInstagramStories() {
    guard let imagePNGData = UIImage(named: "myImage").pngData() else { return }
    guard let instagramStoryUrl = URL(string: "instagram-stories://share") else { return }
    guard UIApplication.shared.canOpenURL(instagramStoryUrl) else { return }

    let itemsToShare: [[String: Any]] = [["com.instagram.sharedSticker.backgroundImage": imagePNGData]]
    let pasteboardOptions: [UIPasteboard.OptionsKey: Any] = [.expirationDate: Date().addingTimeInterval(60 * 5)]
    UIPasteboard.general.setItems(itemsToShare, options: pasteboardOptions)
    UIApplication.shared.open(instagramStoryUrl, options: [:], completionHandler: nil)
}

我应该怎么做才能没有收到错误?

标签: iosswiftinstagram-apiinstagram-story

解决方案


尽量只放<string>instagram</string>. 不需要完整路径,而是方案 url 的基础。

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

推荐阅读