即使添加异常,也无法通过HTTP加载图像

时间:2017-07-16 20:56:16

标签: ios twitter react-native

在我的应用中,我想显示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,但这也没有用。

我哪里错了?

1 个答案:

答案 0 :(得分: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中的值,您应该没问题。