【问题标题】:Unable to load images over HTTP even after adding exceptions即使添加了异常,也无法通过 HTTP 加载图像
【发布时间】:2017-12-21 08:12:07
【问题描述】:

在我的应用程序中,我想显示 Twitter 用户的个人资料图片,但 Twitter 通过 HTTP 提供链接:

http://pbs.twimg.com/profile_images/843199968018157568/zHovYMDk_normal.jpg

我更新了我的 info.plist 以包含 Twitter 用于他们的个人资料图片的域:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>pbs.twimg.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

但是,我仍然无法加载图像。我也试过NSAllowsArbitraryLoads,但也没有用。

我哪里错了?

【问题讨论】:

  • 将您的代码粘贴到您使用该网址的位置。您是否从控制台收到任何有关传输安全的消息?

标签: ios twitter react-native


【解决方案1】:

如果您check the documentation,您会看到图片链接与 https 链接一起返回:

...
"profile_image_url": "http://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png",
...

所以使用来自profile_image_url_https 的值应该没问题。

【讨论】:

  • 谢谢特伦斯,真不敢相信我错过了!你知道为什么我的 info.plist 中的异常不起作用吗?
  • 抱歉 JmJ - 我不是 iOS 开发人员。
猜你喜欢
  • 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
相关资源
最近更新 更多