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 Apples's Push Notification Service (APNs for short) and push notifications for Android devices via Google’s GCM/FCM (Google/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.
N.B. To integrate successfully you will need to have your xtremepush App Key, APNS certs for iOS and, FCM Sender ID 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:
- Connecting your app to the platform
- Getting push certs or API keys
A full Unity integration guide is given below.
- 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
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. There are instructions for the Legacy (Ant/Eclipse) process available here: https://support.xtremepush.com/hc/en-us/articles/115004760629
- 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 please 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:
NOTE: 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
- 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 XP classes.
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.
- 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', scrolling to the 'Signing' section and adding your team to 'Development Team'.
- 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);