I have an Ionic 3 app. I recently added the iOS platform.
When i run it on iOS (emulator and device) all the server requests that has headers fail with the error
To avoid CORS problem specially in iOS
you must use @ionic-native/http plugin which is actually Advanced HTTP plugin for API calling.
Follow below steps to use this plugin
Step 1: Add Http native plugin
$ ionic cordova plugin add cordova-plugin-advanced-http
$ npm install --save @ionic-native/http
Installation Link : HTTP
Step 2: Import HTTP native plugin in your file where you wants to cal API.
import { HTTP, HTTPResponse } from '@ionic-native/http';
Step 3: How to use this plugin for API call ?
constructor(public httpPlugin: HTTP) {
}
//Set header like this
this.httpPlugin.setHeader("content-type", "application/json");
//Call API
this.httpPlugin.get(this.url, {}, {}).then((response) => {
//Got your server response
}).catch(error => {
//Got error
});
Hope this will help you.
I have same issue in android, rest api not working in android emulator or device and give error: Response with 0 for Url: null. and finally i got solution that there is cordova platform android version issue, if there is cordova Android version is 6.3 then it’s working properly but it there is cordova Android version is 7.0 or 7.1.1 then it’s not working for me.
So, I think in ios you should check your ios platform version and then try again. You can check ios or android version using cli command. ionic info
Also check your all cordova plugins is installed or not. If someone is missing then install it manually and check again. You can check your cordova plugins using cli command. cordova plugin -ls
I think it is helpful you.
Thanks