Push Setup - optimove-tech/Optimove-SDK-Unity GitHub Wiki

Optimove SDK provides all functionality to handle push registration & notifications using FCM and APNS.

Additional project configuration

Android

  1. Add google-services.json file from your Firebase app 'General' settings to the /Assets/OptimoveConfigFiles folder of your Unity project. See below how to obtain the json.
  2. in the /Assets/Plugins/Android/baseProjectTemplate.gradle file uncomment:
 // classpath 'com.google.gms:google-services:4.3.14' 
  1. in the /Assets/Plugins/Android/launcherTemplate.gradle file uncomment:
 // implementation platform('com.google.firebase:firebase-bom:28.2.0')
 // implementation 'com.google.firebase:firebase-messaging'

 ...
        
 // apply plugin: 'com.google.gms.google-services'

iOS

No additional steps needed.

Platform configuration

Android

Set up a Firebase Project & enable FCM

Set up an FCM project and configure push for your app.

Optimove requires a service account to execute campaigns for your FCM project. This service account should contain a custom role with just one permission - cloudmessaging.messages.create (you can read about custom roles here, about this specific permission here)

Follow these steps to generate this key:

  1. Go to your Google Cloud Platform console
  2. Navigate to IAM & Admin
  3. Navigate to Roles
  4. Click on "Create Role" at the top
  5. Fill the fields (As a name you can choose something like 'Optimove FCM')
  6. Click on "Add Permissions"
  7. Search for cloudmessaging.messages.create and choose it
  8. Click create
  9. Navigate to Service Accounts
  10. Click on "Create Service Account" at the top
  11. Select the custom role you created in 8
  12. Click done
  13. Click on the service account you generated
  14. Generate a key to this service account

If you have multiple App projects (for example, one for production and one for staging), you must perform this step for each project.

Please note it is the Google Service Account private key JSON file that needs to be uploaded to your mobile UI, not the Google Services JSON file you include in your app project.

Configure Push in your Optimove UI

Access your Optimove UI and select your app, then select Messaging, Configuration.

Access your Optimove dashboard and select 'Settings' then under the 'OptiMobile' section, select 'Mobile Push Config'

Click the cog icon in the row for Android and in the popup when prompted enter the credentials for FCM.

iOS

Generate credentials

In order to generate a P8 key for Apple services first access your account at https://developer.apple.com/ and select 'Certificates, Identifiers & Profiles', then select 'Keys' on the left.

Select 'Create a Key' and on the form 'Register a New Key' enter a meaningful name such as 'APNS Access Key' and check the 'Enable' checkbox for 'Apple Push Notifications service (APNs)', click 'Continue'.

On the confirmation screen double check the APNs enablement is set then click 'Register'

On the final screen take note of your KeyID and download the key. Note that you can only download the key once, if lost the key must be revoked and re-created.

Downloading the key will save a .p8 file with the access credentials.

You now have all the details to configure your Mobile push channel. Access your Optimove dashboard and select 'Settings' then under the 'OptiMobile' section, select 'Mobile Push Config' and click the cog next to the Apple icon. Select APNs P8 and select your file, enter your other details and click 'Configure'.

Usage examples (C#)

To register for push notifications call:

Optimove.Shared.PushRegister();

The following sample code shows how to use Optimove to handle push notifications.

Optimove.Shared.SetPushOpenedHandler((PushMessage push) => {
    // Called when a user taps on a push notification or its action buttons
});

Optimove.Shared.SetPushReceivedHandler((PushMessage push) => {
    // Called when a push is received with your app in the foreground
});

To unregister from push notifications call:

Optimove.Shared.PushUnregister();