Installation and initialization

AppMetrica Push Unity is a plugin for the Unity3d game platform that includes support for the AppMetrica Push SDK for the Android and iOS platforms.

Before using the AppMetrica Push Unity plugin, you need to enable and initialize the AppMetrica Unity plugin version 3.0.0 or later.

Attention. To update the plugin, delete the Assets/AppMetricaPush directory and import the new plugin version (pay attention to the Android configuration).
  1. Integrating the plugin
  2. Configuring the plugin

Integrating the plugin

Step 1. Download the AppMetrica Push Unity plugin.

Step 2. Add the plugin to the project — open the project in Unity Editor and import the AppMetricaPush.unitypackage plugin (Assets → Import Package → Custom Package).

Step 3. Open the Assets/AppMetricaPush/ folder and drag the AppMetrica prefab to the project's main stage.

If the plugin is integrated this way, the AppMetricaPush script on the added prefab automatically initializes the AppMetrica Push SDK.

The added AppMetricaPush prefab is a singleton. It isn't deleted when switching to a new Unity stage, and it deletes other objects that the AppMetricaPush script is installed on.

Configuring the plugin

Step 1. To send notifications to devices with iOS version 7 and higher, make the following changes to the application code:

void Start()
{
  #if UNITY_IPHONE || UNITY_IOS
    UnityEngine.iOS.NotificationServices.RegisterForNotifications (
      UnityEngine.iOS.NotificationType.Alert |
      UnityEngine.iOS.NotificationType.Badge |
      UnityEngine.iOS.NotificationType.Sound, true);
  #endif
}
Tip. You can add a new script (Add Component → New Script) to the existing AppMetricaPush prefab and add code to implement the Start() method for the script.

Step 2. After configuring push notifications for iOS and compiling the project, make changes in the Preprocessor.h file in XCode:

#define UNITY_USES_REMOTE_NOTIFICATIONS 1
Note. The AppMetrica Push Unity Plugin uses “swizzling”: it intercepts the execution of certain methods of the UnityAppController class by using the ObjectiveC runtime. The code is in the AppMetricaPush/Plugins/iOS/YMPBridge.m file.