How to use the https://github.com/chemerisuk/cordova-plugin-idfa plugin in Ionic v3.
I had some issues using the example provided so I had to call the exec directly:
// first install the plugin // cordova plugin add cordova-plugin-idfa // npm i cordova-plugin-idfa --save // add permissions to config.xml under ios platform <platform name="ios"> <edit-config target="NSUserTrackingUsageDescription" file="*-Info.plist" mode="merge"> <string> My tracking usage description </string> </edit-config> </platform>
// has to be called after platform is ready // this.platform.ready().then(() => {} askTrackingPermission() { if (this.platform.is('cordova') && this.platform.is('ios')) { if (window.cordova) { console.log('trying to request permission '); window.cordova.exec(win, fail, 'idfa', "requestPermission", []); } } function win(res) { console.log('success ' + JSON.stringify(res)); } function fail(res) { console.log('fail ' + JSON.stringify(res)); } } readTrackingPermission() { if (this.platform.is('cordova') && this.platform.is('ios')) { if (window.cordova) { window.cordova.exec(win, fail, 'idfa', "getInfo", []); } } function win(res) { console.log('success ' + JSON.stringify(res)); } function fail(res) { console.log('fail ' + JSON.stringify(res)); } }
Also, you can only test this from the iOS simulator (or device) running 14.5.1+ iOS. In your iOS device settings check privacy->tracking (setting) it has to be allowed to ask. And you will only be able to ask the user once.
Good luck!