Ionic 3 api not working in device

I have an API and it’s working perfectly in the ionic serve using CORS. But When I build it device it’s not working.

The CORS is usually for the browser if I remember correctly.

You need to remove it when building on mobile.

Typing from phone.

What the error you get?

Have you installed whitelist plugin

Solved this problem by using this.

 if (this.plt.is('mobileweb') == true){
    this.APIUrl = '/matcheslive';
  }else{
    this.APIUrl = 'https://api.wh.geniussports.com/v1/basketball/competitions/19816/matcheslive';
  }

Sorry you can get more example, dont work httpClienteModule?

What did you do to work on iOS device, I also had a problem with http request api

Hi @Armando1986 I used proxy for http api request.

sorry you can help, or show more example, how can use this proxy, i have a problem with api in iOS device

you had to uninstall or use Wkwebview plugin?

Few day I also facing api call failed in ios only then I resolved issue from server side(enable cors), now it is working fine.

my problem is that I can not touch the server side since it is a private api, but on the Android device it works but iOS does not

Right, I had faced same issue.
This is wkwebview issue in ios.

Due to immediate requirement I have changed my server side so didn’t checked alternative option.

There is three option you can try:

  1. use native htttp plugin (most recommended, please try. I didn’t tried so can’t guarantee)
    https://ionicframework.com/docs/native/http/

  2. remove wkwebview plugin (working but not recommended)

  3. setup proxy(in my case didn’t work in ios. it was working in browser and android).
    https://ionicframework.com/docs/cli/configuring.html#service-proxies

ok server side that you recommend? some instruction of what you did, I would appreciate it

Read my reply properly. I have recommended 1 option.

1)use native htttp plugin (most recommended, please try. I didn’t tried so can’t guarantee)

Use ionic native plugin.

I made the change for HTTP native and it does not work either, I do not find what to do, it only tells me that I must uninstall Wkwebview but it does this that other things do not work

I see that you used iOS device as you did you can help me thank you very much

Can you please send screenshot of debug consle on your ios?

I solved the problem I had to go to the side of the server placing:

header (‘Access-Control-Allow-Origin: *’);
header (“Access-Control-Allow-Methods: GET, OPTIONS”);

and using the following:

@Armando1986 I am also enable cors in server.
wkwebview removing is not recommended.