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.
Follow the steps below:
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.
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
Alternatively, if you want to register in a custom way, you can add the registration code in your Objective-C code.
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.
To implement push notifications with your Unity Android project, you will need to follow the below steps:
On Android, you can setup Firebase Cloud Messaging through Gradle.
Go to the project folder -> Assets -> Plugins -> Android. Open the mainTemplate.gradle file. Uncomment the Firebase dependencies.
compile 'com.leanplum:leanplum-fcm:' + LP_VERSION
apply plugin: 'com.google.gms.google-services'
Set the desired firebase-messaging version.
Add your google-services.json file in the Assets folder. You can also add it after the project is exported depending on your setup.
Add the Google Server API key in the Leanplum App settings on the Dashboard.
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.
Once you've set up push notifications, test that it is working properly by sending a push notification to your development devices.