I’d love some help here because this has driven me a bit crazy for two days now.
Our Ionic 3 app works fine in the browser and on iOS and Android devices. It uses the Angular HTTPClient for all its api calls and all those calls are over https. Because of the CORS issue that occurs on iOS Devices we use the ionic-native-http-connection-backend plugin and this has always worked well. In the app module we use the following code which ignores this plugin for Android devices as CORS has never been an issue for us on Android:
// see https://github.com/sneas/ionic-native-http-connection-backend/issues/15
{
provide: HttpBackend,
useFactory: (platform: Platform, nativeHttpBackend: NativeHttpBackend, httpXhrBackend: HttpXhrBackend) => {
if (platform.is('android')) {
return httpXhrBackend;
} else {
return new NativeHttpFallback(platform, nativeHttpBackend, httpXhrBackend);
}
},
deps: [Platform, NativeHttpBackend, HttpXhrBackend]
},
I have now migrated this application to Ionic 5 and Angular 10 and although everything is working ok in the browser and on iOS, when the app opens up and the user tries to login on Android, the initial POST call results in a CORS error - something I’ve never had on Android devices and something that does not occur on the same test devices when using the Ionic 3 version of our app.
If I change the above code so that the nativeHTTPFallback occurs for Android as well as IOS then the CORS error disappears but NOTHING happens - there is no response from the server, nothing at all.
Does anyone have any idea why I might be running into these issues with Ionic 5 and Angular 10? Surely I should be able to use the Angular HTTPClient on Android devices in an Ionic 5 app?
I did make a test call with the Ionic native HTTP i.e using
import { HTTP } from '@ionic-native/http/ngx';
and that appeared to work. However, our app makes extensive use of an http-interceptor and it looks like that doesn’t work with the native http - I tried logging something from the interceptor and nothing appeared.
Another option might be the Capacitor Community HTTP plugin but I have no idea if that would work with the interceptor either?
Really struggling to work out why this won’t work in Ionic 5 / Angular 10 so any help or advice would be appreciated!