cordova-plugin-idfa + Ionic
wo-github opened this issue · comments
Hello,
could you post a example how to integrate this plugin in a Ionic App?
Sorry, I have no experience with ionic.
@wo-github you could try to ask @adamduren
In Ionic you can access it globally in a component, service, etc, as you would with any other global variable. However Angular recommends using their dependency injection system to make it easier to test by providing an easy way to mock dependencies.
Ionic has ionic-native
which provides utilities to make it easier to build providers for Angular which wrap cordova apis but one is currently not available for this plugin. An example where I've done this in the past can be seen in this PR.
The simplest way without depending on globals in your components and services is to go the Angular only route. Here's some code which should closely
import { Platform } from 'ionic-angular';
import { Injectable } from '@angular/core';
@Injectable()
class IDFAService {
constructor(private platform: Platform) {}
public getInfo(): Promise<string> {
return this.platform
.ready()
.then(() => cordova.plugins.idfa.getInfo())
}
}
@NgModule({
// Other NgModule fields ...
providers: [
// Other providers ...
IDFAService,
],
})
export class AppModule {
}