Phonegap (Application error… Network error occured)

元气小坏坏 提交于 2019-12-10 14:06:24

问题


I have created a build using phonegap. In the index.html file i have written a simple iframe for loading a website. Its working when i take the local url from the phonegap. But its not working if i upload the whole build as a zip in phonegap and then download the apk file from it. Then tried to install that apk in phone its showing the application error.

I have already checked the access origin and also tried to give the domain name inside it. But its not at all working. Can anybody please help me on this.

config.xml and index.html given like this below

<access origin="*"/>

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <title>Testing</title>
    </head>
    <body>

<iframe src="http://www.w3schools.com" height="640px" width="100%" frameborder="0" scrolling="yes">
</iframe>

    </body>
</html>

回答1:


I had this same problem and found an answer here: Application error issue in android emulator "There was an network error"

Solution was to add cordova whitelist.

$ cordova plugin add cordova-plugin-whitelist




回答2:


You have made a common mistake. You need to apply the whitelist system. It is required as of Cordova Tools 5.0.0 (April 21, 2015). For Phonegap Build, that means since cli-5.1.1 (16 Jun 2015)

This whitelist worksheet should help.
HOW TO apply the Cordova/Phonegap the whitelist system

Add this to your config.xml

<plugin name="cordova-plugin-whitelist"      source="npm" spec="1.1.0" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->

NOTE: YOUR APP IS NOW INSECURE. IT IS UP TO YOU TO SECURE YOUR APP.

Add the following to your index.html

<meta http-equiv="Content-Security-Policy" 
         content="default-src *; 
                  style-src * 'self' 'unsafe-inline' 'unsafe-eval'; 
                  script-src * 'self' 'unsafe-inline' 'unsafe-eval';">

NOTE: YOUR APP IS NOW INSECURE. IT IS UP TO YOU TO SECURE YOUR APP.



来源:https://stackoverflow.com/questions/34960386/phonegap-application-error-network-error-occured

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!