← back


Cross-platform Features


IDFA & Google Advertising IDs

IDFA

iOS's ID For Advertising can be retrieved at any point with

var advertisingId = NativeEssentials.Instance.AdvertisingId;

Note: See iOS Features page for IDFV retrieval

GAID (Google Advertising ID)

GAID retrieval is automatically triggered at startup. you can subscribe to be notified when retrieval is complete by using the following callback, and declaring it as early as possibe in your application lifecycle (we recommend the Awake method).

NativeEssentials.OnGoogleAdvertisingIdRetrieved += (gaid) =>
{
    Debug.Log(string.Format("[Info] Retrieved Google Advertiser ID as: {0}", gaid));
};

If you wish to retrieve it at any other point, it should will be available via

var advertisingId = NativeEssentials.Instance.AdvertisingId;

Note: In order to retrieve the GAID, you will need to include Google Play Game Service in ypur project.


Native App Version

The native app version can be retrieved on both iOS and Android with:

var version = NativeEssentials.Instance.VersionNumber;

Note: The value retrieve will be versionName for Android, and CFBundleShortVersionString for iOS.


Native App Build Number

The native app build number can be retrieved on both iOS and Android with:

var buildNumber = NativeEssentials.Instance.BuildNumber;

Note: The value retrieved will be versionCode for Android, and CFBundleVersion for iOS.


Native Package Name/Bundle ID

The native bundle ID can be retrieved on both iOS and Android with:

var bundleId = NativeEssentials.Instance.BundleIdentifier;

Note: The value retrieved will be package for Android, and CFBundleIdentifier for iOS.


Device Family (tablet/phone)

NativeEssentials can accurately determine if your game is running on tablet or phone. Use the following to return either a string value of phone or tablet.

var deviceFamily = NativeEssentials.Instance.DeviceFamily;


Local Notifications

With NativeEssentials, you can schedule a local notification with the native iOS, for delivery in the future. This is possible on both iOS and Android calling the following method:

NativeEssentials.Instance.ScheduleLocalNotification("Notification title", "notification body", 90);

Notes:

  1. The third parameter is the delay in seconds. Calling the example would result in a local push notification delivered 90 seconds from the time of invocation.
  2. For iOS, you will need to request permission be the notification delivery will be allowed (see the Request Notification Permissions section in the iOS Features page for details),
  3. Local notifications will only be delivered if you app is suspended or in the background - not while it is in the foreground.


Native Alerts

You can display native alerts on both iOS and Android by invoking the following command:

DialogConfig dialogConfig = new DialogConfig(dialogTitle: "Important!",
    dialogMessage: "This is a great game",
    yesBtnLabel: "Yes",
    noBtnLabel: "No");

NativeEssentials.Instance.ShowNativeAlert(dialogConfig);

For displaying a single button, simply pass an empty string to for the noBtnLabel parameter of 'DialogConfig`, e.g.:

DialogConfig dialogConfig = new DialogConfig(dialogTitle: "Important!",
    dialogMessage: "This is a great game",
    yesBtnLabel: "Okay",
    noBtnLabel: string.Empty);

If you wish to be notified of the players selection, register the following callback prior to invoking NativeEssentials.Instance.ShowNativeAlert. Note that the callback parameter will be a bool indicating if a positive or negative selection was made by the player:

NativeEssentials.OnAlertCallback += (positiveResponse) =>
{
    Debug.Log(string.Format("[Alert] Got alert feedback - has positive response: {0}", positiveResponse));
};


Native Crashes

In some cases, it might be useful during development to trigger a native crash that is not managed by Unity. You can do this on both iOS and Android with:

NativeEssentials.ForceNativeException();