Skip to content

About

OneSignal makes engaging customers simple and is the fastest, most reliable service to send push notifications, in-app messages, SMS, and emails. This plugin makes it easy to integrate your Unity game with OneSignal. https://onesignal.com

Topics

Resources

Contributing

Stars

226 stars

Watchers

47 watching

Forks

Repository files navigation

OneSignal Unity SDK

⚠️ Migration Advisory for current OneSignal customers

Our new user-centric APIs and v5.x.x SDKs offer an improved user and data management experience. However, they may not be at 1:1 feature parity with our previous versions yet.

If you are migrating an existing app, we suggest using iOS and Android’s Phased Rollout capabilities to ensure that there are no unexpected issues or edge cases. Here is the documentation for each:

iOS Phased Rollout

Google Play Staged Rollouts

If you run into any challenges or have concerns, please contact our support team at support@onesignal.com


A free email, sms, push notification and in app messaging solution for mobile applications built through Unity.

OneSignal provides a full array of omni-channel messaging solutions across:

  • Push Notifications (mobile & web)
  • In App Messages
  • SMS
  • Email

And via many additional platforms. Check them all out!

Table of Contents

Requirements

  • A OneSignal Account if you do not already have one
  • Your OneSignal App ID which you can find under Settings > Keys & IDs
  • Unity 6 (6000.0.23f1) or newer. Unity 2022.3 projects can use 6.0.x.
  • Android Builds: Target API Level 33 or higher
  • iOS Builds: Xcode with network access to GitHub. The SDK adds OneSignal to the exported Xcode project as a Swift package, so CocoaPods is not required.
  • In order to test push notifications you will need
    • An Android 7 or newer device or emulator with "Google Play Store (Services)" installed
    • An iOS 15 or newer device (iPhone, iPad, or iPod Touch)

Push Notification Credentials

You must generate the appropriate credentials for the platform(s) you are releasing on:

Installation

Upgrading from 2.x.x to 3.x.x?
Please check out our v2 to v3 migration guide.

Upgrading from 3.x.x to 5.x.x?
Please check out our v3 to v5 migration guide.

Upgrading to 6.x.x?
Version 6 uses Unity's External Dependency Manager. If your project still contains Google's legacy EDM4U under Assets/ExternalDependencyManager, select Use Unity's External Dependency Manager when prompted. After confirming that your other plugins support Unity EDM, delete the legacy Assets installation so only one dependency manager remains.

Version 6.1.0 adds OneSignal to iOS builds as a Swift package instead of CocoaPods, and requires Unity 6. See the v5 to v6 migration guide.

  1. Add the OneSignal Unity SDK as an available asset to your account by clicking Add to My Assets from our listing on the Unity Asset Store.
  2. Find the package waiting for you to download by clicking Open in Unity from that same page. This will open the Unity Editor and its Package Manager window.
  3. Install OneSignal SDK Android and/or OneSignal SDK iOS from the product. Unity installs OneSignal SDK Core automatically as a dependency.
  4. Open Window > OneSignal SDK Setup and complete the remaining platform setup steps.

No scoped npm registry is required.

Platform Configuration

iOS

After building in Unity and exporting the XCode project follow these steps:

  1. Open Unity-iPhone.xcworkspace if the build created one, otherwise Unity-iPhone.xcodeproj. A workspace exists when External Dependency Manager runs pod install for other CocoaPods dependencies. Xcode resolves the OneSignal Swift package the first time it opens the project.

  2. Click on the Unity-iPhone project and its similarly named target and select the Signing & Capabilities tab.

  3. From here check Automatically manage signing, on the prompt click Enable Automatic, and select your Team.

    automatically manage signing

  4. Scroll down to App Groups and click on the refresh button.

    NOTE: You may have to press this a few times as it will ask you for each signing type.

    refresh app groups

  5. Repeat the same steps above but for the OneSignalNotificationServiceExtension target this time.

    extension signing and groups

  6. App Groups should now be provisioned for you going forward for your iOS bundle id, even on clean builds.

  7. Make sure all Targets have Enable Bitcode set to No in Build Settings.

Android

  1. From the Unity Editor, navigate to Edit > Project Settings > Player and click the Android settings tab.
  2. Expand Publishing Settings and enable:
    • Custom Main Gradle Template
    • Custom Gradle Properties Template
  3. Navigate to Assets > External Dependency Manager > Android Resolver > Force Resolve and resolve your Android dependencies.

Most of the Android setup was already handled during installation!

The only thing remaining is to setup your own notification icons. You can do this be replacing the example icons located at Assets/Plugins/Android/OneSignalConfig.androidlib/src/main/res with your own. There is a complete guide for this in the plugin's README. See our Customize Notification Icons page for additional details.

Disable Location Module (Optional)

By default, the OneSignal Unity SDK includes OneSignal's native location module so OneSignal.Location works without extra setup. If your app does not use location features, you can exclude the native location module from iOS and Android builds. There are two ways to opt out:

  • Editor toggle (interactive): enable Project Settings > OneSignal > Disable Location Module in the Unity Editor before resolving Android dependencies or building iOS. This is persisted per project in ProjectSettings/OneSignalSettings.json.

  • Environment variable (CLI/CI): set ONESIGNAL_DISABLE_LOCATION=true (or 1) in the environment before launching Unity, for example:

    ONESIGNAL_DISABLE_LOCATION=true /path/to/Unity -batchmode -quit -projectPath . -buildTarget iOS -executeMethod BuildScript.BuildiOSSimulator

When set, the environment variable takes precedence over the Editor toggle, so headless builds can opt out without changing project settings.

With the location module disabled, Android resolves OneSignal's native modules without the location artifact and iOS links the OneSignal Swift package without the OneSignalLocation product. OneSignal.Location.RequestPermission() and OneSignal.Location.IsShared = ... no-op on native builds without the location module, and OneSignal.Location.IsShared returns false.

When toggling the flag, clear stale native outputs (the generated Xcode project, Gradle caches, and prior Build/ artifacts) so a previously linked location module isn't reused.

Disable In-App Messages Module on iOS (Optional)

Some App Store reviewers have rejected apps over the web view OneSignal uses to display in-app messages. If your app doesn't use in-app messages, you can leave the OneSignalInAppMessages module, which contains that web view, out of iOS builds:

  • Editor toggle: enable Project Settings > OneSignal > Disable In-App Messages Module (iOS). This is saved in ProjectSettings/OneSignalSettings.json.
  • Environment variable: set ONESIGNAL_DISABLE_IN_APP_MESSAGES=true (or 1) before launching Unity. It takes precedence over the Editor toggle.

With the module disabled, iOS links the OneSignal Swift package without the OneSignalInAppMessages product. On iOS, OneSignal.InAppMessages methods do nothing and log a warning, Paused returns true, and no in-app message events fire. Android builds are unaffected.

When you change the setting, build iOS with Replace, not Append, so a previously linked module isn't kept.

Usage

Follow the Unity SDK setup guide to initialize OneSignal. A complete development demo is available in examples/demo.

Initialization

Prefab

Located in the com.onesignal.unitysdk.core package we've include a simple prefab which initializes OneSignal. You can easily find it using the Asset search bar to find OneSignalController.prefab and making sure to select All or In Packages for your search option. Drag the prefab into your very first scene, fill in the App Id, and you are immediately ready to go!

Code

To get started add the following code in an appropriate place such as the Start method of a MonoBehaviour early in your application's lifecycle.

// Replace 'YOUR_ONESIGNAL_APP_ID' with your OneSignal App ID from app.onesignal.com
OneSignal.Initialize("YOUR_ONESIGNAL_APP_ID");

You are now ready to start sending and receiving notifications and in-app messages. For additional information please see our complete OneSignal Unity SDK docs.

API

See OneSignal's OneSignal SDK Reference page for a list of all available methods.

Change Log

See this repository's releases for a complete change log of every released version.

Support

Please visit this repository's Github issue tracker for feature requests and bug reports related specifically to the SDK.

For account issues and support please contact OneSignal support from the OneSignal dashboard.

License

Modified MIT License

About

OneSignal makes engaging customers simple and is the fastest, most reliable service to send push notifications, in-app messages, SMS, and emails. This plugin makes it easy to integrate your Unity game with OneSignal. https://onesignal.com

Topics

Resources

Contributing

Stars

226 stars

Watchers

47 watching

Forks

Releases

Packages

Used by

Contributors

Languages