Hi,
Is there a way to use Cordova-HTTP native plugin in ionic 2 instead of http object. Since Apple doesn't accept apps that doesn't provide IPV6 only connections.
I have found this plugin https://github.com/wymsee/cordova-HTTP but I am not able to use it in ionic 2 / Typescript
Best regards
You could use XHRBackend to provide an Http implementation using cordova-http
Yes you can use that plugin.
Add declare var cordovaHTTP: any to the top of the page that you need to use the plugin in, and just follow their documentation for usage.
Make sure to provide fallbacks in case the plugin isn't found or if you are running on a browser. These are things that Ionic Native handles for you automatically but it won't be able to handle it for you this time since you're using an external plugin.
@ihadeed,
I've same issue and tried to use Cordova plugin. I receive all time a 415 http error (Media type unsupported). I use same request headers as I did with http object. it's a content-type header. I sniffed my mobile's network to watch my request, all seems to be right. Is there any intention to create an Ionic-native 2 version of this plugin ?
@tamerbak it's added now, please update to latest version
This plugin is amazing, it makes the same calls in 25-50% of the time the Angular 2 HTTP service takes. Thanks for suggesting it @jakjoud
@ihadeed Thank you for intergating it 馃憤
Thank you @ihadeed, yes indeed, being "native" will accelerate Http requests on devices.
@ihadeed can you perhaps explain or share some code of which is the best way to provide fallbacks in case the plugin isn't found or if you are running on a browser.
For now we have an injector for angular's http where we do something, we provide the injector in our app.module.ts
export function httpFactory(backend: XHRBackend, options: RequestOptions) {
return new HttpService(backend, options);
}
providers: [
{
provide: Http,
useFactory: httpFactory,
deps: [
XHRBackend,
RequestOptions
]
},
So in our app we can inject angular's http and instead is using HttpService. We would like to do the same thing now with ionic native HTTP and keep a fallback with angular's http for browser usage.
Can you help which are the best way to do this?
@mburger81 have you found way how to do it? Did you create new http backend for the cordova http plugin? I found https://github.com/sneas/ionic-native-http-connection-backend
Most helpful comment
@tamerbak it's added now, please update to latest version
This plugin is amazing, it makes the same calls in 25-50% of the time the Angular 2 HTTP service takes. Thanks for suggesting it @jakjoud