简体   繁体   English

Ionic2 / Cordova无法连接到互联网

[英]Ionic2/cordova fail to connect to the internet

I have created an app using ionic2 and using a firebase to connect in facebook. 我创建了一个使用ionic2并使用firebase在facebook中进行连接的应用程序。 So my problem is the app when is used to in web browser works fine, but when I try to run on my device I get this error? 所以我的问题是该应用程序在网络浏览器中使用时能正常工作,但是当我尝试在设备上运行时出现此错误?

code: "auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred."

Ok, I know the device can get connection, so my device has a 4g connection and wifi and works fine in other apps. 好的,我知道设备可以连接,所以我的设备具有4g连接和wifi,并且可以在其他应用中正常工作。 So, I verified the cordova config.xml and shows me <access origin="*"/> , I read the generated AndroidManifest and have a <uses-permission android:name="android.permission.INTERNET" /> . 因此,我验证了cordova config.xml并显示了<access origin="*"/> ,阅读了生成的AndroidManifest并显示了<uses-permission android:name="android.permission.INTERNET" />

I don't know what is worng, it`s my first time with ionic and cordova, anyone can help me? 我不知道这是什么,这是我第一次接触离子和科尔多瓦,有人可以帮助我吗?

my package.json: 我的package.json:

    {
  "name": "xxx",
  "author": "Ricardo",
  "homepage": "http://www.example.com",
  "private": true,
  "scripts": {
    "build": "ionic-app-scripts build",
    "watch": "ionic-app-scripts watch",
    "serve:before": "watch",
    "emulate:before": "build",
    "deploy:before": "build",
    "build:before": "build",
    "run:before": "build"
  },
  "dependencies": {
    "@angular/common": "^2.0.0",
    "@angular/compiler": "^2.0.0",
    "@angular/compiler-cli": "0.6.2",
    "@angular/core": "^2.0.0",
    "@angular/forms": "^2.0.0",
    "@angular/http": "^2.0.0",
    "@angular/platform-browser": "^2.0.0",
    "@angular/platform-browser-dynamic": "^2.0.0",
    "@angular/platform-server": "^2.0.0",
    "@angular/router": "^2.0.0-rc.2",
    "@ionic/storage": "^1.0.3",
    "angularfire2": "^2.0.0-beta.5",
    "cordova": "^6.3.1",
    "firebase": "^3.5.0",
    "ionic-angular": "^2.0.0-rc.1",
    "ionic-native": "^2.2.7",
    "ionicons": "^3.0.0",
    "ng2-image-lazy-load": "^2.0.9",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.21"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^0.0.33",
    "@types/request": "0.0.30",
    "ng2-facebook": "0.0.3",
    "ng2-facebook-sdk": "^1.0.0",
    "reflect-metadata": "^0.1.2",
    "typescript": "^2.0.3"
  },
  "description": "xxx: ",
  "cordovaPlugins": [],
  "cordovaPlatforms": [],
  "config": {
    "ionic_rollup": "./config/rollup.config.js",
    "ionic_copy": "./config/copy.config.js"
  }
}

and my config.xml: 和我的config.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="br.com.xxx.app" version="2.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>xxx</name>
  <description>An awesome Ionic/Cordova app.</description>
  <author email="xxx@gmail.com" href="http://www.example.com">xxx Team</author>
  <content src="index.html"/>
  <access origin="*"/>
  <allow-intent href="http://*/*"/>
  <allow-intent href="https://*/*"/>
  <allow-intent href="tel:*"/>
  <allow-intent href="sms:*"/>
  <allow-intent href="mailto:*"/>
  <allow-intent href="geo:*"/>
  <platform name="android">
    <allow-intent href="market:*"/>
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*"/>
    <allow-intent href="itms-apps:*"/>
  </platform>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreenDelay" value="0"/>
  <preference name="FadeSplashScreen" value="false"/>
  <preference name="FadeSplashScreenDuration" value="0"/>
  <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
  <feature name="StatusBar">
    <param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <plugin name="cordova-plugin-facebook4" spec="~1.7.4">
    <variable name="APP_ID" value="99999999999"/>
    <variable name="APP_NAME" value="xxx"/>
  </plugin>
</widget>

In your index.html, I assume that you already have Content-Security-Policy . 在您的index.html中,我假设您已经具有Content-Security-Policy
Try replacing it with the following one. 尝试将其替换为以下之一。

<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready file:; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; img-src * data: 'unsafe-inline'">  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM