1

当我尝试将图像分享到 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)
}

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

4

2 回答 2

2

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

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>instagram</string>
</array>
于 2019-07-15T20:35:26.820 回答
1

好的,我通过以下答案解决了错误:https ://stackoverflow.com/a/38393379/5061249

我还试图将 LSApplicationQueriesSchemes 定义为 dict :(

于 2019-07-15T20:40:18.860 回答