Integration
The base service will come packaged in the DarkMatter unity package
Integration - iOS
No additional steps required
Integration - Android
-
google-service.json: Place the google-service.json file downloaded from the Firebase in the [You project root]/Assets/Libraries/Push/Editor/Android folder
-
Android manifest: Add the following lines under the application node of your custom unity Android manifest.
<!-- Push Notifications - -->
<service android:name="com.magmic.darkmatter.push.PushUnityPlugin">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Note: there are additional optional properties support, see the Firebase notification documentation.
- build gradle: Add the following entries to your Unity mainTemplate.gradle file.
buildscript {
dependencies {
classpath 'com.google.gms:google-services:3.2.0'
}
}
allprojects {
repositories {
maven { url "https://maven.google.com" }
}
}
dependencies {
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
}
At the very bottom of your build gradle file add the following line.
apply plugin: 'com.google.gms.google-services'
Export - Android
The standard gradle export will include everything needed to use push.
Export - iOS
IMPORTANT After exporting in your XCode project make sure to compatibilities > Push Notifications to ON or the push service will not work. See the Apple push documentation for more details.
Usage
To use the Push service you’ll first need to initialize it. An initialization hive node comes with the base DarkMatter project that will initialize and setup the service.
initialization
If you don’t use the PushNode then you’ll need to manual call PreInitialize and Initialize functions on the instances manually and handle any errors.
Push.Instance.PreInitialize();
...
Push.Instance.Initialize()
.Then(rsp =>
{
//Success
})
.Catch(err =>
{
//Fail
});
Getting push permissions
On Android the initial push permissions will be granted when the user installs the application. On iOS you’ll need to request permission which will trigger the native iOS push notification permission dialog.
Push.Instance.requestPermissions()
.Then(rsp =>
{
//Success
})
.Catch(err =>
{
//Fail
});
IMPORTANT The iOS native push permission dialog will only ever present once per install.
Tracking a users push token updates
If initialized using the PushNode the service will automatically try and track the status of a users push token. On launch it will check for a new token and when the local userId changes on the DarkMatter instance.
Manifest
- A new “pushService” manifest node should be added to your manifest using the hope dashboard, for more details on what each node does see the Push Manifest Keys documentation.
"pushService": {
"enabled": true,
"permissionTimeout": 2,
"removeOldTokenOnUpdate": true
}
- A new optional endpoint has been added to the gameService endpoints node.
{
"gameServie":
{
"endpoints": {
"updatePushToken": {
"path": "/notifications/{0}/{1}/token/update"
}
}
}
}