Unity Push Guide

Prerequisites


Unity Apps on the Push Dashboard

In order to use Unity Applications on the Upsight Push Dashboard, you will have to create separate Apps for iOS and Android versions of your Application.

To send Push Messages to your Unity Apps, you will need to complete the Integration steps for your specific platform (i.e. creating a GCM Project for Android and enabling APNS for iOS).

  • For more information on the iOS specific implementations of Push, please see the iOS Push Guide.

  • For more information on the Android specific implementations of Push, please see the Android Push Guide.

Handling and Integrating Push


Integrate Push

To integrate push notifications in your app, you must register for push notifications at app launch in order to correctly handle pending notifications received after your app has been killed. For Android, you must also pass in the GCM Project Number when initializing the plugin, as shown below.

void Start()
{
#if UNITY_ANDROID
    Upsight.init( androidAppToken, androidAppSecret, gcmProjectNumber );
#else
    Upsight.init( iosAppToken, iosAppSecret );
#endif

    // Make an open request at every app launch
    Upsight.requestAppOpen();

    // Register for push notifications at every app launch
    Upsight.registerForPushNotifications();

    // Make a content request at every app launch
    Upsight.sendContentRequest( "app_launch", true );
}

Handling a Push

The Upsight Unity Plugin will handle receiving push notifications for you. However, we strongly recommend that you override the default behaviour on iOS when receiving push notifications that trigger content units and URIs.

The default behaviour on iOS is to immediately display content units or redirect to URIs that are triggered by push notifications. This is fine when your app is in the background, but can cause user experience issues when your app is in the foreground when a push notification arrives. The default behaviour may interrupt a user that is deeply engaged in your app.

Therefore, we recommend that you disable displaying content units and redirecting to URIs triggered by push notifications when your app is in the foreground. The sample code below shows how this can be done.

void OnApplicationPause( bool pauseStatus )
{
    // Make an open request whenever app is resumed
    if( !pauseStatus )
        Upsight.requestAppOpen();

#if UNITY_IPHONE
    // On iOS, toggle opening of content units and URLs triggered by push notifications.
    // Only enable this when app is paused to avoid interrupting users.
    Upsight.setShouldOpenContentRequestsFromPushNotifications( pauseStatus );
    Upsight.setShouldOpenUrlsFromPushNotifications( pauseStatus );
#endif
}

There is no additional coding required for Android.

Passing Data


For information on using Passing Data, please visit the Passing Data page for the specific platform your app is deployed to.

Using Device Identifiers


For information on using Device Identifiers, please visit the Device Identifiers page for the specific platform your app is deployed to.

Troubleshooting


No Push Registration Occurring When Using Prime31 Plugin.

If you're using a Prime31 plugin that has push functionality, there is a chance Upsight Push will not register successfully. We recommend deleting the AppControllerPushAdditions files.

Additional Troubleshooting Support

For more troubleshooting tips, go to our main Unity troubleshooting guide.