Close

Push Notifications Setup

Omniata allows you to send Push Notifications to iOS and Android devices. This is also supported for Unity3D integrations. Configuring support for sending notifications from Omniata involves the same procedure for iOS and Android. On this guide we present the steps for each platform.

This guide enables Omniata to schedule and send notifications for users that have this feature enabled in their Apps. To enable or disable a user from receiving notifications refer to the the Standard Event Types section, and Application Settings to enable notification tracking. By default Omniata will not enable these features.

Content:

Overview

The overall setup is described in the diagram below.

enter image description here

Setting up your application to receive push notifications (magenta arrows)
It involves setting up your application to be able to receive push notifications. The flow is Omniata-independent, i.e. something you need to do in order to support push notifications in your application.
Registering the push credentials in Omniata (green arrows)
The credentials are needed in order for Omniata to be able to deliver the push notifications through Apple/Google on your behalf. For iOS push notifications, the original unformatted iOS certificate is needed (.pem).
Registering iOS Device Token in Omniata (blue arrows)
Omniata needs this information in order to deliver the push notifications. The iOS Device Token is registered to Omniata by sending it with a specific event type. The event types for each platform are described in the Standard Event Types.
Verifying notification delivery (green arrows)
With a test device, and after that, setting up push notification Campaigns in Omniata. Once everything is set up and the first Device Token events are received, you can test sending push notification to your test device (check section below for this).

For more information about setting up live campaigns, please see section Campaigns & A/B Test.

Setup in iOS

You will require an iPad or iPhone and a iOS Developer Program membership. You cannot push to iOS simulator.

Generating the SSL certificate on Mac

First, Log in to the iPhone Developer Connection Portal and click App IDs. Next, ensure you have created an App ID without a wildcard. Wildcard IDs cannot use the push notification service. For example, our iPhone application ID looks something like AB123346CD.com.abc.iphone.

Make sure that push notification is activated for this application :

enter image description here

You don’t need to configure it yourself. Insead we are going to use the fastlane pem tool, which will take care of configuring your certificates.

The the fastlane pem tool will also generate a pem key, the output will look like this :

enter image description here

You will then need to create a provisioning profile for your app. Once created it should specifically list Push Notifications in the enabled services :

enter image description here

Note : make sure that your ios app has the updated provisioning profile.

Finally, you need to enable the Push Notification capability in the app settings:

enter image description here

Registering and Verifying Your Certificate

To register Push Credentials in Omniata navigate to your project, and further Integrate -> Push And Email -> New.

If you need to test push notification for iOS development build, check the Is Development checkbox. Once you have uploaded the certificate, you can check the upload was successful by checking the hash of the certificate file. You can get the hash of your certificate on your computer with execute the following command in your terminal.

md5 <certificate.pem>          # Mac OS X
md5sum <certificate.pem>       # Linux

Note: You cannot download the certificates from Omniata. This is to prevent someone with access to your project from taking the certificate and use it outside of Omniata.

Sending Device Token with SDK

To enable Push Notifications via Omniata SDK, calling this method will tell Omniata that the user is eligible to receive push notifications.

[iOmniataAPI initializeWithApiKey:@"<API_KEY>" UserId:@"<USER_ID>" AndDebug:YES];
...
[iOmniataAPI enablePushNotifications:deviceToken];

To disable via Omniata SDK, calling this method will tell Omniata that the user is no longer eligible to receive push notifications.

[iOmniataAPI disablePushNotifications];

Sending Device Token from Server

To enable using the REST API:

GET https://example.analyzer.omniata.com/event 
?api_key=ae4398de
&uid=e439da31f399c23a
&om_event_type=om_apns_enable
&om_device_token=<valid_device_token>

To disable using the REST API you can notify Omniata that the user is no longer interested in receiving push notifications. Please note that you can always re-enable at any time.

GET https://example.analyzer.omniata.com/event 
?api_key=ae4398de
&uid=e439da31f399c23a
&om_event_type=om_apns_disable
&om_device_token=<valid_device_token>

Setup in Android

Before you begin, make sure to set up the Google Play Services SDK. You need this SDK to use the GoogleCloudMessaging methods.

Generating a Google API Key

To create a Google API project:

  1. Open the Google Developers Console.
  2. If you haven’t created an API project yet, click Create Project.
  3. Supply a project name and click Create.
  4. Once the project has been created, a page appears that displays your project ID and project number. For example, Project Number: 670330094152.

Copy down your project number. You will use it later on as the GCM sender ID. The next step is to enable the GCM service:

  1. In the sidebar on the left, select APIs & auth.
  2. In the displayed list of APIs, turn the Google Cloud Messaging for Android toggle to ON.

Finally, to obtain an API key:

  1. In the sidebar on the left, select APIs & auth > Credentials.
  2. Under Public API access, click Create new key.
  3. In the Create a new key dialog, click Server key.
  4. In the resulting configuration dialog, supply your server’s IP address. You can either:
    • Use 0.0.0.0/0 as IP.
    • Ask Omniata Customer Support for the IP address of Omniata server (more security).
  5. Click Create.

In the refreshed page, copy the API key. You will need the API key later on to configure Push Notifications in Omniata.

Note: If you need to rotate the key, click Regenerate key. A new key will be created. If you think the key has been compromised and you want to delete it immediately, click Delete.

Registering and Verifying Your API Key

To register Push Credentials in Omniata navigate to your project, and further Integrate -> Push And Email -> New. Once you have uploaded the API key, you can check the upload was successful by checking the hash of the key. You can get the hash of your certificate on your computer with execute the following command in your terminal.

md5 -s <GCM key>                     # Mac OS X
echo -n <GCM key> | md5sum           # Linux

Note: You cannot display the GCM keys from Omniata. This is to prevent someone with access to your project from taking the GCM keys and use it outside of Omniata.

Sending Registration ID with SDK

Follow the GCM client guide to know how to retrieve the Registration ID in your Android Application.

To enable notifications calling this method will tell Omniata that the device is eligible to receive push notifications.

Activity activity = this;
Omniata.initialize(activity, "<API_KEY>", "<USER_ID>");
...
Omniata.enablePushNotifications("<REGISTRATION_ID>");

To disable notifications calling this method will tell Omniata to stop sending push notifications to the user:

Omniata.disablePushNotifications();

Sending Registration ID from Server

You can also send the user’s push token directly to our REST API.

GET https://example.analyzer.omniata.com/event 
?api_key=ae4398de
&uid=e439da31f399c23a
&om_event_type=om_gcm_enable
&om_registration_id=<valid_registration_id>

Similarly, to disable you can use:

GET https://example.analyzer.omniata.com/event 
?api_key=ae4398de
&uid=e439da31f399c23a
&om_event_type=om_gcm_disable
&om_registration_id=<valid_registration_id>

Push Notifications for Unity3D Plugin

Unity3D with iOS

Start by following the steps to obtain the certificate in Mac. Once the certificate has been uploaded to Omniata you can proceed with the next steps.

Retrieve the device token and send it to Omniata with EnablePushNotificationsFromTokenBytes. In order to retrieve the device token you need to use native Unity class NotificationServices. You can find more information in Unity guides for iOS Notification Services.

Once you have obtained the device token, you need to send the following event :

byte[] token = NotificationServices.deviceToken;
Omniata.Instance.EnablePushNotificationsFromTokenBytes(token);

Alternatively you can call the REST API as specified above.

Unity3D with Android

Start by following the steps to obtain the GCM API Key. Once the certificate has been uploaded to Omniata you can proceed with the next steps.

Retrieve the GCM token as a string and send it with AutoEnableOmPushNotifications. Unity3D does not provide a direct access to the android native interface for retrieving the token, so you will need to write the android interface to retrieve it or use a plugin such as Android Native Plugin.

To disable notifications, call this method to tell Omniata that the user is no longer eligible to receive push notifications:

Omniata.Instance.DisableOmPushNotifications();

Alternatively you can call the REST API as specified above.

Testing Notifications Delivery

To test Push Notifications in device, you’ll need to have your push notification credentials (Apple certificate or Google API key) registered in Omniata as well as have your app set up to send the tokens (Apple device token or Android Registration ID) to Omniata and receive remote notifications from Apple or Google.

The following can be used as a test script:

  1. Make sure that your test device has sent its token.
  2. Create a User Profile with the UID of your test device.
  3. Navigate to a suitable Push Notification content and access the Test mode from upper right corner. If you don’t yet have any Push Notification content available, create one for example by using simple defaults.
  4. Select your test profile and right environment.
  5. After you see confirmation “This uid has a device token associated.”, you can send a Push Notification to your test device. As the message is sent through Apple or Google, it may take a few seconds to arrive to your device.

If the notification does not arrive, recheck that the configuration has been completed. Common causes of missing notifications are:

  • Token and certificate do not match for current build.
  • Certificate is expired.
  • A new Token has been created for the user.
  • JSON in the content is not valid for the platform.

A good rule of thumb is to test that your certificate, token and content combination are working using iOS or Android native tools. Contact Omniata support in case assistance is needed.

This article was last updated on May 5, 2017 13:03. If you didn't find your answer here, search for another article or contact our support to get in touch.