【问题标题】:Ionic2/cordova fail to connect to the internetIonic2/cordova 无法连接到互联网
【发布时间】:2016-12-07 19:10:05
【问题描述】:

我使用 ionic2 创建了一个应用程序,并使用 firebase 在 facebook 中进行连接。所以我的问题是在网络浏览器中使用的应用程序可以正常工作,但是当我尝试在我的设备上运行时出现此错误?

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

好的,我知道设备可以连接,所以我的设备有 4g 连接和 wifi,并且可以在其他应用程序中正常工作。 所以,我验证了 cordova config.xml 并向我展示了<access origin="*"/>,我阅读了生成的 AndroidManifest 并有一个 <uses-permission android:name="android.permission.INTERNET" />

我不知道什么是wearg,这是我第一次使用ionic 和cordova,有人可以帮助我吗?

我的 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"
  }
}

还有我的 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>

【问题讨论】:

标签: android cordova ionic2


【解决方案1】:

在您的 index.html 中,我假设您已经有 Content-Security-Policy
尝试用下面的替换它。

<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'">  

【讨论】:

  • 这个解决方案对我有用。但是,考虑到该行代码中使用“不安全”的次数,这是一个安全的解决方案吗? :D
最近更新 更多