Skip to content

Unity

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

Download Plugin
Download Sample
Plugin Docs

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

  1. Get the google-services.json from your Firebase console as described here and locate it to your project’s Assets folder. Package name of your app should be added to your Firebase project and persist in the google-services.json file.
  2. Import Unity push notification plugin into your Assets folder in Unity.

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.FcmProjectNumber = "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);
}
}

Enable Push Notifications in the Capabilities section.

Enable Remote notifications for Background Modes in the Capabilities section.

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

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.

Issues with Unity projects with the Pushwoosh plugin installed

If you face the error like the one shown in the picture below, it might be caused by the Unity framework issue with the projects with 3rd-party plugins.

That’s what the Unity resolution note on this issue says:

At some point, UnityFramework runtime together with plugins is loaded at run time by dyld/NSBundle.load. Please keep that in mind while developing a plugin.

Any API-rich initialization on +(load), attribute(constructor), and global object construction code paths should be moved to a later phase preferably after UnityFramework is loaded, and even better when Unity is initialized.

Simple plain data initialization is safe, but API-rich calls that deal with other os parts especially networking and user interface APIs might lead to deadlock leading to watchdog termination.

By doing delayed/lazy initialization you can get better control over initialization order, you can reduce the application load time, and most importantly you avoid possible deadlock.

Possible workaround:

By default, UnityFramework.framework is embedded in Unity-iPhone target and it is not linked with it, UnityFramework is loaded later at runtime and some plugins are sensitive to this initialization path.

Go to Unity-iPhone / Build Phases / Link Binary with Libraries build section and add UnityFramework.framework.

UnityFramework will be loaded at the same time as the main executable.

Share your feedback with us

Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.