本文大部分內容是網上摘錄,mark一下,方便以后查找,
引用地址:http://blog.csdn.net/joyfixing/article/details/52535922
react native開發環境描述:macPro webstorm IOS10.2模擬器
最近練習做項目,用到了網絡請求,我用fetch方式GET方法?請求數據,IOS模擬器一直提示Network Request Failed
我的代碼:
fetch('http://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson.movies);
return responseJson.movies;
})
.catch((error) => {
console.error(error);
});
問題原因:
IOS9引入了新特性App Transport Security (ATS)。新特性要求App內訪問的網絡必須使用HTTPS協議,意思是Api接口以后必須是HTTPS。但是我的項目使用的是HTTP協議,現在也不能馬上改成HTTPS協議傳輸。
替代解決方案
- 在Info.plist中添加NSAppTransportSecurity類型Dictionary。
- 在NSAppTransportSecurity下添加NSAllowsArbitraryLoads類型Boolean,值設為YES