Unity Plugin

Integrating Pushwoosh SDK into your Unity project

Supports iOS, Android, Amazon, Windows Store Apps (Windows 8.1/Phone 8.1/Windows 10)

Note:

iOS Simulator can neither subscribe nor receive push notifications.

To integrate Pushwoosh into your Unity application you need to do simple following steps:

  1. Import Unity push notification plugin into your assets folder in Unity.

unitypackage:

If Pushwoosh.unitypackage import fails, copy Assets/Editor, Assets/Plugins, Assets/Pushwoosh folders from the Sample Project into yours.

AndroidManifest.xml changes

Merge contents of Assets/Plugins/Android/PushwooshAndroidManifest.xml into Assets/Plugins/Android/AndroidManifest.xml. If you don't already have an Android Manifest, rename PushwooshAndroidManifest.xml to AndroidManifest.xml.
Replace PACKAGE_NAME with your project package. Note that in Unity it is called ‘Bundle Identifier’.

  1. Create PushNotificator.cs script and attach it to Camera Object in the scene.
using UnityEngine;
using System.Collections;
 
public class PushNotificator : MonoBehaviour {
    // use for initialization
    void Start () {
        Pushwoosh.ApplicationCode = "ENTER_PUSHWOOSH_APP_ID_HERE";
        Pushwoosh.GcmProjectNumber = "ENTER_FCM_SENDER_ID_HERE";
        Pushwoosh.Instance.OnRegisteredForPushNotifications += OnRegisteredForPushNotifications;
        Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += OnFailedToRegisteredForPushNotifications;
        Pushwoosh.Instance.OnPushNotificationsReceived += OnPushNotificationsReceived;
      	Pushwoosh.Instance.RegisterForPushNotifications ();
    }
 
    void OnRegisteredForPushNotifications(string token)
    {
        // handle here
        Debug.Log("Received token: \n" + token);
    }
     
    void OnFailedToRegisteredForPushNotifications(string error)
    {
        // handle here
        Debug.Log("Error ocurred while registering to push notifications: \n" + error);
    }
     
    void OnPushNotificationsReceived(string payload)
    {
        // handle here
        Debug.Log("Received push notificaiton: \n" + payload);
    }
}

That’s it! How easy is that?

ApplicationCode and GcmProjectNumber should be set before first Pushwoosh.Instance method call

iOS extras

To hide notification alerts when the application is in the foreground, simply set Pushwoosh_SHOW_ALERT value to NO in your Info.plist

XCode

XCode requires Push Notifications to be enabled in Capabilities section in order to register for push notfications.

Enable Push Notifications in the Capabilities section.

Enable Remote notifications for Background Modes in the Capabilities section.

Android extras

To receive push notifications on Android when the application is active without posting the notification to the notification center, set the following line in AndroidManifest.xml to true:

<meta-data android:name="PW_BROADCAST_PUSH" android:value="true" />

Amazon API Key

Get the API KEY from Amazon according to the Amazon guide.
For a pre-release or “debug” version of your app, you must create an API Key and store it as the only data in a file named api_key.txt . The api_key.txt file must be located inside the assets folder for your project.
Note: ADM cannot recognize your API Key if it contains any spaces or line breaks.
For a release or “production” version of your app, you may not need to create an API Key. Only if you sign the release version of your app using your own certificate, must you create an additional API Key for the release version of your app. Otherwise, if you allow Amazon to sign your app on your behalf, you do not need to create an additional API Key.

Windows Store Apps

Follow the guide below

You might need to select WSAPlayer platform for the libraries in Plugins/WSA as per screenshot below.

You also need to Associate App with the Store in exported Visual Studio project. And don't forget to set Notifications->Toast Capable in the project manifest.

Unity Plugin

Integrating Pushwoosh SDK into your Unity project