当我在模拟器中运行我的离子应用程序时:
离子模拟ios --target =“iPhone-6”
我没有问题访问互联网 . 但是当我在调用后尝试从XCode运行应用程序时
离子构建ios cordova准备
该应用无法访问互联网 .
我已将 cordova-plugin-whitelist 插件添加到我的应用程序中,以及添加
<allow-navigation href =“*”/> <allow-intent href =“http:// * / *”/> <allow-intent href =“https:// * / *”/>
到我的config.xml
和
<meta http-equiv =“Content-Security-Policy”content =“default-src'self'data:gap:https://ssl.gstatic.com; style-src'self''unsafe-inline'; media -src *“>
到我的index.html
代码:
import { Headers, Http, Response } from '@angular/http';
...
public login(url: string, params: any): Observable<any> {
return this.post(url, params) //I have logged the URL and it's fine!
.map((response: any) => {
...
})
.catch((error) => {
console.log("Error: " + JSON.stringify(error));
});
}
错误输出如下:
{
"_body": {
"isTrusted": true
},
"status": 0,
"ok": false,
"statusText": "",
"headers": {},
"type": 3,
"url": null
}
我看过以下内容:
-
https://forum.ionicframework.com/t/ionic-run-android-works-but-apk-does-not-access-internet/3867
-
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
EDIT
我已经看到ionic-cli github页面上仍有一个与此相关的未解决问题 .
EDIT 2
Cordova CLI:6.2.0 Ionic Framework版本:2.0.0-rc.1 Ionic CLI版本:2.1.8 Ionic App Lib版本:2.1.4 Ionic App脚本版本:0.0.30 ios-deploy版本:1.9.0 ios -sim版本:5.0.11操作系统:macOS Sierra Node版本:v6.7.0 Xcode版本:Xcode 8.1 Build版本8B62
4 回答
你有没有照顾App Transport Security?
从iOS9开始,Apple要求您允许info.plist中的特定域或明确允许所有外部加载(Apple不推荐这种加载,但最简单的测试用例是查看问题是否由ATS引起) .
有关App Transport Security的更多信息:https://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/在您的info.plist中
基本上你必须在info.plist中指定以下内容(同样:不推荐外部加载的一般容差,你可以通过上面的链接找到有关如何指定域的详细信息:)):
所以根据这个SO Answer:
这导致我使用Safari在模拟器上调试iOS应用程序(现在也拒绝连接到互联网) . 我看到了错误:
事实证明METEOR过去曾遇到过类似的问题,但是在cordova上通过添加以下行解决了这个问题:
哪个让我访问网络服务!
我通过将下面的代码添加到后端索引页面来解决它(我的后端是CI)
并使用以下代码从移动端使用API获取数据
我一直在研究离子3项目,我也面临着一个问题,即离子ios应用程序无法连接到互联网并且总是出错 - > {"isTrusted" = true}但从未连接到互联网...我也尝试了应用自定义元标记,离子上的代理以及在互联网上给出的其他内容,但我的问题通过删除一个名为 webkit 插件的插件特别为ios解决...在Android应用程序上运行良好的插件但是在ios 9及以上版本上引起了问题 .