Skip to content

Unity

Download Plugin
Download Sample
Plugin Docs

Integration steps

To integrate Pushwoosh into your Unity application, follow these steps:

  1. Download 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.

Android integration

Update AndroidManifest.xml

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 referred to as the ‘Bundle Identifier’.

Register push notifications

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);
}
}

iOS Integration

Hiding notification alerts

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

Enable push notifications in Xcode

Xcode requires Push Notifications to be enabled in Capabilities section in order to register for push notfications. For this, go to CapabilitiesEnable Push Notifications.

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="false" />

Amazon integration

Obtain an API Key from Amazon

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.

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 integration

  1. Add link.xml to your Assets/ directory with the following content:
<linker>
<assembly fullname="PushSDK" preserve="all"/>
</linker>
  1. You also need to Associate App with the Store in exported Visual Studio project. Make sure your app is signed with a certificate matching your Publisher Identity.

Opt in the Internet (Client) capability in Capabilities tab of your .appxmanifest in the exported Visual Studio project.

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.

The Unity resolution note on this issue states:

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 the Unity-iPhone target but is not linked to it. As a result, UnityFramework is loaded later at runtime, and some plugins may be sensitive to this initialization path.

To resolve this, go to Unity-iPhoneBuild PhasesLink Binary with Libraries build section and add **UnityFramework.framework**.

This ensures that UnityFramework loads simultaneously with 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.