App run perfectly on browser but not on real device


#1

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.


#2

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?


#3

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.


#4

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?


#5

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));
}


#6

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:*" />

#7

ok let me try this solution.


#8

I tried above but still its not working


#9

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


#10

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.


#11

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.


#12

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


#13

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!


#14

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


#15

@bpcuong2013 Please try to remove platform and add it again


#16

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!


#17

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.


#18

Can you try this.

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

#19

Thanks! That worked for me.