0

My problem:

When developing with the Phonegap Developer app, everything is working OK. But after I build my app with Phonegap Build, my AJAX requests seem not to work.

Important notes:

  • I did the white-listing described here
  • It is working with the Phonegap Develop app (on both iOS and Android)
  • Only the calls to my API seem not to work. (to give an example, i made a login screen, but I got no response of it)
  • I made an error-callback in my AJAX requests with a notification-alert. This is also only working in the Phonegap Developer App.

The steps I took:

  • Create the app and tested it with the Phonegap Develop app
  • Zipped my project and uploaded it to Phonegap Build
  • Rebuild my project in the Phonegap Build to get the latest version
  • Scanned the project with the QR code
  • Installed the project and ran the app

Versions of dependencies:

  • AngularJS v1.2.13 (angular.js, angular-animate.js, angular-route.js)
  • Bootstrap v3.3.6
  • jQuery v1.11.3
  • Laravel 5.1 (For the API development)
Community
  • 1
  • 1
Justin La France
  • 789
  • 8
  • 21

1 Answers1

2

@JustDevelop,
you have made two (2) common mistakes.

  1. First, you can NOT use files created with Phonegap Desktop App and use those files on Phonegap Build. You can use those files with Phonegap CLI, but not Build. It works differently. You need to start with your own boilerplate, or a known working boilerplate.

  2. You will need to use the whitelist system, but it has changed ALOT in three (3) years. Do not follow any post, blogs, or advice more than 6 months old - as of today (2015-12-23)

On #1, here is boilerplate to get you started Phonegap--Generic-Boilerplate7 In addition, the following blog post will work for development and make you familiar with what you need.
An HTML Boilerplate for Phonegap
Use the both as a reference for production, but not release

On #2, as Joerge and jcesarmobile alluded to you may need to add the whitelist system to your app. If you have inline or block Javascript in your index.html, you will need to use CSP. If not, then you just need to use the whitelist plugin with the filters. If not, then the whitelist plugin with the filters may be enough.

inline javascript <button onclick="doSomething();">do something</button>

block javascript <script>doSomething() function() {return something;}</script>

If you do in fact have a whitelist issue, use this Guide and the code that follows:

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 This is your CSP fix.

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

Lastly FWIW, you might consider opening a github account. Public accounts are free. Private accounts the charge for. You can transfer you code direct from your computer, to github, to Phongap Build.

Also, please let us know, what, if anything helped fix your issue.