With the Xtremepush bindings for Unity, you can add Xtremepush to both iOS and Android apps built with Unity.

Platform Specific Information

Xtremepush supports push notifications for iOS devices via Apple's Push Notification Service (APNs) and for Android devices via Google’s FCM (Firebase Cloud Messaging for Android) service. This page contains Unity specific instructions but you will need to connect your iOS and Android app to the platform separately.

👍

To integrate successfully you will need to have your Xtremepush App Key, APNS certs for iOS, and Google project number and FCM API key for Android. These are used to connect your app to the platform and the Apple and Google push services. You will find links to documentation on connecting to the platform below:

Initial Setup

  • Download the latest Unity plugin file from the Mobile Frameworks page
  • Extract the zip file and copy the contents of the Assets folder into the Assets folder in your Unity project (it is important to keep the file structure of the Assets folder in your Unity project the same as it is in the extracted zip file)
  • If you have other plugins installed in your project, the Assets/Plugins/Android and Assets/Plugins/iOS folders may already exist, in which case you can merge the files from the extracted zip file into the corresponding locations in your project
  • Open up your Unity IDE to allow the Assets to be synchronised from the filesystem
  • Once this has been completed, you can proceed to the platform-specific instructions below for Android and iOS

Android setup

The initial setup above will pull in the library files, but the SDK will still need to be configured. The following instructions are for projects that can use Gradle/Android Studio in the build process.

  • If you have Android Studio installed, open the UnityAndroid project in it (if you do not have this installed, a text editor can be used instead).
  • Edit the UnityApplication.java file located in the extracted folder at UnityAndroid/unityapplication/src/main/java/com/xtremepush/unity
    • Swap in your real Xtremepush App key and GCM Sender ID
    • Configure any other options required in the PushConnector initialization
    • If you require a callback to a C# function when a message is opened, edit the messageClicked() function as necessary
  • Build the UnityAndroid/unityapplication module
    • In Android Studio this can be built by selecting the unityapplication module in the project view on the left of the window and then, in the menus at the top of the screen, selecting Build > Make Module unityapplication
    • This can also be built from the command-line instead by navigating to UnityAndroid and running the following command: ./gradlew

Troubleshooting

If you are getting an error with the Android SDK location such as: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable, this can be resolved by making a file in the root directory called local.properties, and adding to it the following line:

sdk.dir=/PATH_TO_YOUR_ANDROID_SDK
  • Copy the unityapplication-debug.aar file from UnityAndroid/unityapplication/build/outputs/aar to the Assets/Plugins/Android folder in your project, replacing the placeholder file
  • In the Unity Build Settings, change the Build System to Gradle. This is necessary to correctly build all Xtremepush classes.

iOS Setup

The Initial setup above will pull in the library files but the SDK will still need to be configured as follows:

  • In your project folder, edit the XtremepushAppController.mm file in Assets/Plugins/iOS as follows:
    • Add your real App key between the quotation marks on line 18
    • Configure any other options required in your project
  • If you are using location functionality in the app please add an entry for NSLocationAlwaysUsageDescription in your plist file after building the project from the Unity IDE
  • In player settings, scroll down to the Identification section. Here you can enter the bundle ID for your app, and also the provisioning profile associated with that bundle ID.

Troubleshooting

If you build the app now, you might receive an error saying Signing for "YOUR_APP" requires a development team. This problem is easily fixed by opening the XCode project. Then in the Build Settings, scroll to the Signing section and add your team to 'Development Team'.

Usage

If you want to send tags or events to our platform from your app, this can be achieved from your C# classes with the following:
Add an entry to pull in the Xtremepush.cs class file

using Xtremepush;

Then call the public functions that have been exposed through this class, e.g.,

XtremepushBinding.hitTag ("TagTitle");
XtremepushBinding.hitTag ("TagTitle", "TagValue");
XtremepushBinding.hitEvent ("EventTitle");
XtremepushBinding.hitImpression ("ImpressionTitle");
XtremepushBinding.sendTags ();
XtremepushBinding.sendImpressions ();
XtremepushBinding.setExternalId ("EXTERNAL_ID");
XtremepushBinding.setSubscription (false);

👍

Make sure you set the user ID

It is recommended that at this stage you use our SDK method to set user IDs by following our dedicated guide to ensure devices can be associated and targeted in your campaigns by your own unique identifier.