Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic proxy works on ionic serve, not on ios simulator or device

I have a simple web service in my ionic app... it connects to remote server for simple tasks.

The proxy is setup in ionic like this:

  "proxies": [{
     "path": "/api",
     "proxyUrl": "http://example.com/api"
   }]

and the calls are to "/api". These resolve properly to http://example.com/api in localhost browser (using ionic serve).

But in xcode, the url is resolved to:

file:///api

I can't find anything on this specifically. How show I be calling for ios?

like image 825
lilbiscuit Avatar asked Nov 19 '15 20:11

lilbiscuit


People also ask

Does ionic work on iOS?

Because of this foundation in web technologies, Ionic can run anywhere the web runs — iOS, Android, browsers, PWAs, and more.

What is Ionic App on Iphone?

Ionic provides a set of tools for building native iOS and Android applications, and mobile-ready Progressive Web Apps, using familiar web libraries, frameworks, and languages. Ionic Capacitor is a cross-platform native bridge that allows you to turn any web project into a native iOS or Android mobile application.


1 Answers

I faced the same issue while running on Android device, The solution is simple, point to note here is the proxy we are using to handle the CORS issue and this is the issue only in perticular with the desktop browser, so while using ionic serve we need proxy and we dont need to use proxy for other devices. I have used below condition in the service to handle this with out doing any further code changes while building for any target platform.

var APIUrl = '/myproxies';
if (this.platform.is('core') == true){
    APIUrl = '/myproxies';
}else{
    APIUrl = 'http://api.sample.com/SomeSampleAPIProvider';
}
this.http.get(APIUrl+"/Json").map(res => res.json()).subscribe(
    data => {.....

can refer this link to know usage details of this.platform

like image 60
madhav bitra Avatar answered Oct 04 '22 19:10

madhav bitra