Skip to content

Install and initialize the module

This document explains how to install and initialize the 'Push notifications' module in the Hive Axyl SDK. Before you install and initialize the module, install the Hive Axyl SDK.

Note
  • If you have not created a project and an App ID and checked the security key in the Hive Console, first create the app information.
  • If you have not installed the Hive Axyl SDK yet, first install the Hive Axyl SDK.


1. Install the push module

Token registration and notification consent management for remote push are provided in the com.hive.axyl.push package. Add this package with the method you used in SDK installation.

If you use Packages/manifest.json (recommended), add it to dependencies. Replace the version values with the actual release versions.

"dependencies": {
  "com.hive.axyl.core": "PLACEHOLDER_AXYL_CORE_VERSION",
  "com.hive.axyl.push": "PLACEHOLDER_AXYL_PUSH_VERSION"
}

After installation, if the using Hive.Axyl.Push; statement causes no compile errors, the package is installed correctly.

To use remote push notifications for each OS, also install the Add-on packages you need.

Feature Package Initialization extension Resolve target
Android remote push (FCM) com.hive.axyl.push.addon.fcm AddFCM() IFCMPlugin
iOS remote push (APNs) com.hive.axyl.push.addon.apns AddAPNS() IAPNSPlugin

To get device tokens issued through FCM on Android, also install the FCM plugin in FCM integration setup. To get APNs tokens issued and handle reception callbacks on iOS, complete APNs integration setup.


2. Initialize the push module

Register the push module together in the builder of SDK initialization (HiveBootstrap.Initialize). Because initialization is called only once in the entire app, if you already initialize other modules, add only AddPush() to the same Initialize call.

using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity;   // HiveBootstrap
using Hive.Axyl.Push;         // AddPush extension

var config = CoreConfig.CreateBuilder("{appId}")
    .SetZone(Zone.Sandbox)   // Development and test environment. Use Zone.Real for production builds
    .Build();

HiveBootstrap.Initialize(config, builder =>
{
    builder.AddPush();
    // If you use it with other modules such as authentication, register them all at once.
    // (The AddAuth/AddToken extensions require using Hive.Axyl.Auth;.)
    // builder.AddAuth().AddToken().AddPush();
});

AddPush() automatically uses the server address of the environment specified with SetZone. After registration, get the push feature with HiveCore.Resolve<IPushService>() and use it. Because the push API uses the logged-in session, you must complete login before calling it.

3. Initialize OS Add-ons

Add only the OS-specific Add-ons for the features you need. The following example registers FCM remote push on Android and APNs remote push on iOS.

using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity;
using Hive.Axyl.Push;
#if UNITY_ANDROID
using Hive.Axyl.Push.Addon.FCM;
#elif UNITY_IOS
using Hive.Axyl.Push.Addon.APNS;
#endif

HiveBootstrap.Initialize(config, builder =>
{
    builder.AddPush();

#if UNITY_ANDROID
    builder.AddFCM();
#elif UNITY_IOS
    builder.AddAPNS();
#endif
});

OS Add-on ports are registered only on the supported target OSs. If the same code can run in the Editor or on another OS, wrap the HiveCore.Resolve<T>() call in an OS branch, or check with HiveCore.TryResolve<T>() before use.

Next steps