Skip to content

Unity SDK basic integration guide

This guide walks you through integrating the Pushwoosh Unity SDK into your application.

Prerequisites

Anchor link to

Integration steps

Anchor link to

1. Add Pushwoosh Unity SDK

Anchor link to

Add the following to your Packages/manifest.json:

Packages/manifest.json
{
"dependencies": {
"com.pushwoosh.unity.core": "6.3.0",
"com.pushwoosh.unity.android": "6.3.0",
"com.pushwoosh.unity.ios": "6.3.0"
},
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.org",
"scopes": ["com.pushwoosh"]
}
]
}

Add only the platform packages you need. For example, omit com.pushwoosh.unity.android if you only target iOS.

2. Install External Dependency Manager

Anchor link to

The Android part of the SDK requires External Dependency Manager for Unity (EDM4U) to resolve native Android dependencies. Skip this step if you only target iOS.

Add the following scoped registry to your Packages/manifest.json:

{
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": ["com.google.external-dependency-manager"]
}
]
}

Then add the package to your dependencies:

"com.google.external-dependency-manager": "1.2.183"

3. Choose how the iOS SDK is added

Anchor link to

By default, the iOS export gets the native SDK from the Swift package Pushwoosh-XCFramework with Swift Package Manager. You don’t need CocoaPods or EDM4U for iOS, and you don’t run pod install.

To change the source of the iOS SDK or add optional modules, open Window > Pushwoosh SDK Setup in the Unity Editor:

  • In iOS SDK from, select Swift Package Manager or CocoaPods.
  • With Swift Package Manager, under Modules (Swift Package Manager only), select the optional modules your app uses: PushwooshLiveActivities, PushwooshInboxKit, PushwooshInApp, PushwooshVoIP, PushwooshForegroundPush, PushwooshKeychain, PushwooshGRPC, PushwooshGeozones. The modules are linked to the app target. To use a module in your own app extension, add it to the extension target in Xcode. With CocoaPods, the export goes without these modules.

The export falls back to CocoaPods, and the Unity console states the reason, when any of these applies:

  • CocoaPods is selected in Window > Pushwoosh SDK Setup.
  • The project already has a PushwooshXCFramework pod, in a *Dependencies.xml file read by EDM4U or in the Podfile. To switch to Swift Package Manager, remove the pod. For Geozones, remove the PushwooshXCFramework/Geozones pod and select PushwooshGeozones in Window > Pushwoosh SDK Setup.
  • The Unity version is earlier than 2021.3.15.
  • Target minimum iOS Version is below 15.0.

With CocoaPods, EDM4U isn’t required. The SDK runs pod install after the export and generates the Podfile itself, unless EDM4U is installed and writes the Podfile instead. If pod install fails, the Unity console shows the error. Run pod install in the exported Xcode project folder.

If your build environment can’t reach github.com, Xcode can’t resolve the Swift package. Select CocoaPods in Window > Pushwoosh SDK Setup for such builds.

The Swift Package Manager export keeps Unity-iPhone.xcworkspace, so build scripts and CI that build the workspace work without changes.

4. Initialize the SDK

Anchor link to

Create a PushNotificator.cs script and attach it to any GameObject in the scene:

PushNotificator.cs
using UnityEngine;
using System.Collections.Generic;
public class PushNotificator : MonoBehaviour
{
void Start()
{
Pushwoosh.ApplicationCode = "XXXXX-XXXXX";
Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnRegisteredForPushNotifications += (token) => {
Debug.Log("Push token: " + token);
};
Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += (error) => {
Debug.Log("Registration failed: " + error);
};
Pushwoosh.Instance.RegisterForPushNotifications();
}
}

Replace:

  • XXXXX-XXXXX with your Pushwoosh Application Code.
  • XXXXXXXXXXXX with your Firebase project number (Android only).

5. iOS native setup

Anchor link to

5.1 Capabilities

Anchor link to

After building the iOS project from Unity, open the generated Xcode project and add the following capabilities in Signing & Capabilities:

  • Push Notifications
  • Background Modes with Remote notifications checked

For Time Sensitive Notifications (iOS 15+), also add the Time Sensitive Notifications capability.

5.2 Info.plist

Anchor link to

Add the Pushwoosh Device API Token to your Info.plist:

Info.plist
<key>Pushwoosh_API_TOKEN</key>
<string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>

5.3 Message delivery tracking

Anchor link to

Add a Notification Service Extension target to your Xcode project. This is required for accurate delivery tracking and Rich Media on iOS.

Follow the native guide to add the extension target.

6. Android native setup

Anchor link to

6.1 Add Firebase configuration file

Anchor link to

Place the google-services.json file into your Unity project’s Assets directory.

6.2 Add Pushwoosh metadata

Anchor link to

Add the Pushwoosh Device API Token to your Assets/Plugins/Android/AndroidManifest.xml inside the <application> tag:

AndroidManifest.xml
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />

7. Run the project

Anchor link to
  1. Build and run the project on your target platform.
  2. Grant permission for push notifications when prompted.
  3. Go to the Pushwoosh Control Panel and send a push notification.

Extended integration

Anchor link to

At this stage, you can send and receive push notifications. The sections below cover the core SDK functionality.

Push notification event listeners

Anchor link to

The SDK provides two event listeners for handling push notifications:

  • OnPushNotificationsReceived — triggered when a push notification arrives
  • OnPushNotificationsOpened — triggered when a user taps a notification

Set up these listeners during SDK initialization:

PushNotificator.cs
void Start()
{
Pushwoosh.ApplicationCode = "XXXXX-XXXXX";
Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnPushNotificationsReceived += (payload) => {
Debug.Log("Push received: " + payload);
};
Pushwoosh.Instance.OnPushNotificationsOpened += (payload) => {
Debug.Log("Push opened: " + payload);
};
Pushwoosh.Instance.RegisterForPushNotifications();
}

User configuration

Anchor link to

Personalize push notifications by identifying users and setting their properties:

// Set user ID for cross-device tracking
Pushwoosh.Instance.SetUserId("user-123");
// Set user email
Pushwoosh.Instance.SetEmail("user@example.com");
// Set user with both ID and email
Pushwoosh.Instance.SetUser("user-123", new List<string> { "user@example.com" });
// Set preferred language
Pushwoosh.Instance.SetLanguage("en");

Tags are key-value pairs assigned to devices, enabling user segmentation and targeted messaging:

// String tag
Pushwoosh.Instance.SetStringTag("favorite_category", "electronics");
// Integer tag
Pushwoosh.Instance.SetIntTag("purchase_count", 5);
// List tag
Pushwoosh.Instance.SetListTag("interests", new List<object> { "sports", "music", "tech" });
// Get all tags
Pushwoosh.Instance.GetTags((tags, error) => {
if (error != null) {
Debug.Log("Error: " + error.Message);
return;
}
foreach (var tag in tags) {
Debug.Log(tag.Key + ": " + tag.Value);
}
});

Track user actions to analyze behavior and trigger automated messages:

// Track a login event
Pushwoosh.Instance.PostEvent("login", new Dictionary<string, object> {
{ "username", "user-123" },
{ "login_type", "email" }
});
// Track a purchase event
Pushwoosh.Instance.PostEvent("purchase", new Dictionary<string, object> {
{ "product_id", "SKU-001" },
{ "price", 29.99 },
{ "currency", "USD" }
});

Communication preferences

Anchor link to

Allow users to opt in or out of push notifications programmatically:

// Enable communication
Pushwoosh.Instance.SetCommunicationEnabled(true);
// Disable communication
Pushwoosh.Instance.SetCommunicationEnabled(false);
// Check current state
bool isEnabled = Pushwoosh.Instance.IsCommunicationEnabled();

Badge management

Anchor link to

Control the app badge number on supported platforms:

// Set badge to a specific number
Pushwoosh.Instance.SetBadgeNumber(3);
// Increment badge
Pushwoosh.Instance.AddBadgeNumber(1);
// Clear badge
Pushwoosh.Instance.SetBadgeNumber(0);

Troubleshooting

Anchor link to

If a push isn’t delivered, find the error code for your platform in Sending errors to see what it means and how to fix it.

If you encounter any issues during the integration process, refer to the support and community section.