App run perfectly on browser but not on real device

I have created an app, based on the iconic 3. The app works perfectly on the browser as I have used HTTP requests but now it’s not working on the real device. The API I used also works fine on the postman. Please suggest what went wrong. And app previously works on the real device too.

But I unable to debug it more. I have installed whitelist plugin.

1 Like

On what platform do you want to run it? Does it open on your device or throw an error in console?
Please also run the following command
ionic info
and post your result.

Have you updated some dependencies or the ionic cli?

I want to run it on android. Yes, it opens up on the device, but when I trying to make any HTTP request it shows nothing when I debug the request it does not show me header and response body whereas browser shows.

Ionic Info:
Your system information:

Cordova CLI: 6.5.0
Ionic Framework Version: 3.0.1
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.0
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.8.0
Xcode version: Xcode 8.3.1 Build version 8E1000a

No I havent update any dependency or cli. I have attached screenshot of http request.

1 Like

Your setting looks fine.

I get the following request with postman:

{
  "data": {
    "results": [],
    "empty_message": ""
  },
  "response_code": 400,
  "err_message": "User API Plugin not found, User is probably not installed"
}

Can you post the file content where you call the request?

1 Like

But I got whole content, in postman.
Here is my code.

this.http.get(lang_url).map(res => res.json()).subscribe(
data => {
this.storage.set(‘serverConfig’, data.data);
},
err => {
console.log(“Error”+JSON.stringify(err));
}

1 Like

Looks like you don’t get any response. You can’t look into incoming requests in your server, right?

If you added whitelist-plugin you could try to add in your config.xml

<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
2 Likes

ok let me try this solution.

I tried above but still its not working

1 Like

Sorry my mistake. That were the wrong lines. try this:
<access origin="*" />
if it is not already in there

An alternative would be to adjust CSP. You can find a description at the bottom of this site:
https://www.npmjs.com/package/cordova-plugin-whitelist

2 Likes

Hey, @Nexi thanks for your help. I able to get rid of this by removing and adding platform. I wish I could have done this before.

2 Likes

Just make sure you are using ionic native http and if you are using angular http it create problem in ios/android device.

So make sure to check this also because I already face this situation.

If you configure your settings correctly angular’s http client should work fine. I have some apps in production that work without any problems.

But I encountered some problems with ionic native http. I would recommend to use angular’s http client if you don’t need any of the following advantages and don’t encounter any problems, because the ionic native http plugin adds at least two more dependencies to your app and in addition increases your app size.

Advantages over Javascript requests:

  • Background threading - all requests are done in a background thread
  • SSL Pinning

Reference

It does not work for me on the real device, but works on emulator. Below is the error

Response {body: ProgressEvent, status: 0, ok: false, statusText: “”, headers: Headers, …}
_ body:ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, …}
_ headers:Headers {headers: Map(0), normalizedNames: Map(0)}
_ ok:false

_ status:0

_ type:3_
_ url:null_
proto:Body {constructor: , toString: }
_ arguments:TypeError: ‘caller’, ‘callee’, and ‘arguments’ properties may not be accessed on strict mode functions or the arguments objects for calls to them_
_ caller:TypeError: ‘caller’, ‘callee’, and ‘arguments’ properties may not be accessed on strict mode functions or the arguments objects for calls to them_

Please help. Thanks!

Hi , I have the same problem , you have any solution?thanks!

@bpcuong2013 Please try to remove platform and add it again

3 Likes

My issue was that the real device could not connect the server because I deployed the server locally on my laptop. My solution is deploying on Heroku, then it works. Thanks!

1 Like

i add and removed the platforms many times but no success found, app is crashing still now. i dont where problem is there. please help me as soon as possible , its urgent.

1 Like

Can you try this.

<allow-navigation href="http://*/*"/>
  <allow-navigation href="https://*/*"/>
1 Like

Thanks! That worked for me.

can you show me exactly how you do it, I am a beginner and got this issue, I can’t seem to solve it. thank you in advance