cordova-plugin-idfaiosx
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Cordova plugin for getting Advertising ID (IDFA or AAID)

Index

Supported Platforms

  • iOS

Installation

$ cordova plugin add cordova-plugin-idfaiosx

API

The API is available on the cordova.plugins.idfa global object.

getInfo()

Returns a Promise<object> with the following fields:

  • trackingLimited: boolean - Whether usage of advertising id is allowed by user.
  • idfa: string (iOS only) - Identifier for advertisers.
  • trackingPermission (iOS 14+ only): number Tracking permission status, available on iOS 14+ devices.

requestPermission()

(iOS only) A one-time request to authorize or deny access to app-related data that can be used for tracking the user or the device. See Apple's API docs for more info on the dialog presented to the user. Available only for iOS 14+ devices.

Returns a Promise<number>. On devices with iOS < 14 the method will return a rejected promise.

Note: You should make sure to set the NSUserTrackingUsageDescription key in your app's Information Property List file, otherwise your app will crash when you use this API. You can do it with the following code in your Cordova project's config.xml:

<platform name="ios">
    <edit-config target="NSUserTrackingUsageDescription" file="*-Info.plist" mode="merge">
        <string>My tracking usage description</string>
    </edit-config>
</platform>

Tracking Permission Values

The tracking permission values are numbers returned by getInfo() and requestPermission(). The possible values are stored in constants on the plugin object. See the example on how to use them.

For the meaning of the values see the tracking transparency API docs:

Constant Value Description
TRACKING_PERMISSION_NOT_DETERMINED 0 User has not yet received an authorization request to authorize access to IDFA
TRACKING_PERMISSION_RESTRICTED 1 User restricted the value returned if authorization to access IDFA
TRACKING_PERMISSION_DENIED 2 The value returned if the user denies authorization to access IDFA
TRACKING_PERMISSION_AUTHORIZED 3 The value returned if the user authorizes access to IDFA

Example

const idfaPlugin = cordova.plugins.idfa;

idfaPlugin.getInfo()
    .then(info => {
        if (!info.trackingLimited) {
            return info.idfa || info.aaid;
        } else if (info.trackingPermission === idfaPlugin.TRACKING_PERMISSION_NOT_DETERMINED) {
            return idfaPlugin.requestPermission().then(result => {
                if (result === idfaPlugin.TRACKING_PERMISSION_AUTHORIZED) {
                    return idfaPlugin.getInfo().then(info => {
                        return info.idfa || info.aaid;
                    });
                }
            });
        }
    })
    .then(idfaOrAaid => {
        if (idfaOrAaid) {
            console.log(idfaOrAaid);
        }
    });

Package Sidebar

Install

npm i cordova-plugin-idfaiosx

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

14.6 kB

Total Files

9

Last publish

Collaborators

  • j-xhesi