Unity SDK basic integration guide
This guide walks you through integrating the Pushwoosh Unity SDK into your application.
Prerequisites
Anchor link toIntegration steps
Anchor link to1. Add Pushwoosh Unity SDK
Anchor link toAdd the following to your 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.
In Unity, go to Window > Package Manager > + > Add package from git URL and add the following URLs one by one:
https://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.corehttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.androidhttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.iosDownload Pushwoosh.unitypackage from GitHub Releases and import via Assets > Import Package > Custom Package.
2. Install External Dependency Manager
Anchor link toThe 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 toBy 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
PushwooshXCFrameworkpod, in a*Dependencies.xmlfile read by EDM4U or in the Podfile. To switch to Swift Package Manager, remove the pod. For Geozones, remove thePushwooshXCFramework/Geozonespod and selectPushwooshGeozonesin 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 toCreate a PushNotificator.cs script and attach it to any GameObject in the scene:
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-XXXXXwith your Pushwoosh Application Code.XXXXXXXXXXXXwith your Firebase project number (Android only).
5. iOS native setup
Anchor link to5.1 Capabilities
Anchor link toAfter 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 toAdd the Pushwoosh Device API Token to your Info.plist:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>5.3 Message delivery tracking
Anchor link toAdd 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 to6.1 Add Firebase configuration file
Anchor link toPlace the google-services.json file into your Unity project’s Assets directory.
6.2 Add Pushwoosh metadata
Anchor link toAdd the Pushwoosh Device API Token to your Assets/Plugins/Android/AndroidManifest.xml inside the <application> tag:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />7. Run the project
Anchor link to- Build and run the project on your target platform.
- Grant permission for push notifications when prompted.
- Go to the Pushwoosh Control Panel and send a push notification.
Extended integration
Anchor link toAt this stage, you can send and receive push notifications. The sections below cover the core SDK functionality.
Push notification event listeners
Anchor link toThe SDK provides two event listeners for handling push notifications:
OnPushNotificationsReceived— triggered when a push notification arrivesOnPushNotificationsOpened— triggered when a user taps a notification
Set up these listeners during SDK initialization:
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 toPersonalize push notifications by identifying users and setting their properties:
// Set user ID for cross-device trackingPushwoosh.Instance.SetUserId("user-123");
// Set user emailPushwoosh.Instance.SetEmail("user@example.com");
// Set user with both ID and emailPushwoosh.Instance.SetUser("user-123", new List<string> { "user@example.com" });
// Set preferred languagePushwoosh.Instance.SetLanguage("en");Tags
Anchor link toTags are key-value pairs assigned to devices, enabling user segmentation and targeted messaging:
// String tagPushwoosh.Instance.SetStringTag("favorite_category", "electronics");
// Integer tagPushwoosh.Instance.SetIntTag("purchase_count", 5);
// List tagPushwoosh.Instance.SetListTag("interests", new List<object> { "sports", "music", "tech" });
// Get all tagsPushwoosh.Instance.GetTags((tags, error) => { if (error != null) { Debug.Log("Error: " + error.Message); return; } foreach (var tag in tags) { Debug.Log(tag.Key + ": " + tag.Value); }});Events
Anchor link toTrack user actions to analyze behavior and trigger automated messages:
// Track a login eventPushwoosh.Instance.PostEvent("login", new Dictionary<string, object> { { "username", "user-123" }, { "login_type", "email" }});
// Track a purchase eventPushwoosh.Instance.PostEvent("purchase", new Dictionary<string, object> { { "product_id", "SKU-001" }, { "price", 29.99 }, { "currency", "USD" }});Communication preferences
Anchor link toAllow users to opt in or out of push notifications programmatically:
// Enable communicationPushwoosh.Instance.SetCommunicationEnabled(true);
// Disable communicationPushwoosh.Instance.SetCommunicationEnabled(false);
// Check current statebool isEnabled = Pushwoosh.Instance.IsCommunicationEnabled();Badge management
Anchor link toControl the app badge number on supported platforms:
// Set badge to a specific numberPushwoosh.Instance.SetBadgeNumber(3);
// Increment badgePushwoosh.Instance.AddBadgeNumber(1);
// Clear badgePushwoosh.Instance.SetBadgeNumber(0);Troubleshooting
Anchor link toIf 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.