2016-07-01 16 views
5

我想在iPhone模擬器在HTTP URI作爲源加載圖像。但是屏幕上沒有顯示任何可以與檢查員看到的線框。 如果你在Android中加載相同的代碼,它工作正常,如果你使用https URI而不是http,它也可以正常工作。通過https陣營本地加載形象工程,而HTTP不起作用

示例代碼:

render() { 
    return ( 
    <View> 
    <Image 
     source={{uri:https://facebook.github.io/react/img/logo_og.png'}} // works 
    // source={{uri: http://facebook.github.io/react/img/logo_og.png'}} // doesn't work 
     style={{width: 400, height: 400}} 
    /> 
    </View> 
); 
} 

回答

5

的問題是,你正在嘗試,因爲它是由蘋果要求從HTTP連接從HTTPS連接加載圖像,而不是。 如果您的代碼與另一個使用https而不是http的uri協同工作,請嘗試。在Android中,它應該可以正常使用http或https。 閱讀更多在https://github.com/facebook/react-native/issues/8520http://www.techrepublic.com/article/wwdc-2016-apple-to-require-https-encryption-on-all-ios-apps-by-2017/

如果你真的想要加載的東西通過http您可以編輯Info.plist文件並添加例外存在。這裏更詳細的信息https://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

0

在info.plist中

<key>NSAppTransportSecurity</key> 
<dict> 
<!--Include to allow all connections (DANGER)--> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
</dict> 
添加
相關問題