Unity push notifications setup
To setup push notification support with your Unity project, Leanplum provides a couple of built-in methods that will help you depending on the platform your game is played on.
Unity iOS Push Setup
Follow the steps below:
STEP 1:
You need to enable your iOS project for push notifications. Add the Push Notifications Capability to the exported iOS project from Unity. You can do this manually from Xcode or through a post-processor build script from Unity.
STEP 2:
You can ask the user to allow your app for remote notifications directly from Unity. This is done by calling the below method after Leanplum starts (Leanplum.start()
). This will register the device through the iOS framework to receive alerts, badges, and sounds - it will directly show the native iOS prompt.
Note that you can use Push Pre-Permission instead of directly showing the native prompt.
// Registers the device through the iOS remote push framework
Leanplum.RegisterForIOSRemoteNotifications();
Alternatively, if you want to register in a custom way, you can add the registration code in your Objective-C code.
STEP 3:
For iOS push notifications to work with Leanplum, you'll also need to upload your .p12 certificates to Leanplum. Refer to the iOS SDK docs for instructions on how to do that.
If you want to use Rich Push Notifications follow the iOS guide on how to enable them.
Unity Android Push Setup
To implement push notifications with your Unity Android project, you will need to follow the below steps:
STEP 1:
On Android, you can setup Firebase Cloud Messaging through Gradle.
STEP 2:
Go to the project folder -> Assets -> Plugins -> Android. Open the mainTemplate.gradle file. Uncomment the Firebase dependencies.
classpath 'com.google.gms:google-services:3.0.0'
compile 'com.leanplum:leanplum-fcm:' + LP_VERSION
compile('com.google.firebase:firebase-messaging:[10.0.0,)')
apply plugin: 'com.google.gms.google-services'
STEP 3:
Set the desired firebase-messaging version.
STEP 4:
Add your google-services.json file in the Assets folder. You can also add it after the project is exported depending on your setup.
STEP 5:
Add the Google Server API key in the Leanplum App settings on the Dashboard.
STEP 6:
Finally, you'll need to add some items to your Android manifest. To access that code, please visit the Android push setup
It's a good practice to show additional information or navigate to the correct part of your app when users open your push notifications. You can do that using Leanplum's in-app messaging, which integrates nicely with push notifications.
Test Push Notifications
Once you've set up push notifications, test that it is working properly by sending a push notification to your development devices.