【问题标题】:React-native loading image over https works while http does not work通过 https 的 React-native 加载图像有效,而 http 无效
【发布时间】:2016-11-04 08:00:16
【问题描述】:

我想通过 http uri 作为源在 iOS 模拟器中加载图像。但是屏幕上没有显示任何东西,除了可以通过检查器看到的线框。 如果您在 Android 中加载相同的代码,它可以正常工作,如果您使用 https uri 而不是 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>  
 );  
}

【问题讨论】:

    标签: ios https react-native info.plist app-transport-security


    【解决方案1】:

    问题是您正在尝试从 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/

    【讨论】:

      【解决方案2】:

      添加 info.plist

      <key>NSAppTransportSecurity</key>
       <dict>
       <!--Include to allow all connections (DANGER)-->
          <key>NSAllowsArbitraryLoads</key>
          <true/>
       </dict>
      

      【讨论】:

      • 在 ios 中适用于我,但在 android 中适用?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 2017-10-30
      • 2023-01-13
      • 2012-09-26
      • 2020-04-03
      • 1970-01-01
      相关资源
      最近更新 更多