map-o file-code-o arrow-directionplatform-webreach-project-type-boarding-passreach-project-type-couponreach-project-type-event-ticketreach-project-type-genericreach-project-type-gift-cardreach-project-type-loyalty-cardreach-project-type-member-card pictures more_vert chain keyboard_arrow_down keyboard_arrow_right

Unity

The Urban Airship Unity Plugin allows a developer to integrate push notification services with Unity apps targeting both Android and iOS. This plugin is designed to be cross-platform, and applications making use of it can leverage the same code on both platforms.

Resources

Requirements

  • Unity 5
  • iOS: Xcode 8+
  • Android: Android SDK installed and updated (requires Android MinSdkVersion = 16)

Setup

Download the latest plugin and import the unitypackage into the unity project: Open Assets -> Import Package -> Custom Package.

Configure Urban Airship Settings: Open Window -> Urban Airship -> Settings and set the Urban Airship settings.

After generating a project for iOS, enable Push Notifications in the project editor’s Capabilities pane:

Notification Service Extension

In order to take advantage of iOS 10 notification attachments, such as images, animated gifs, and video, you will need to create a notification service extension by following the iOS Notification Service Extension Guide.

Send Your First Push Notification

UAirship.Shared.UserNotificationsEnabled = true;

At this point in the guide, if you followed all the steps above you should be ready to send a test push notification to verify everything is set up properly.

Before sending a push, you must enable user notifications. The plugin does not enable user notifications by default in order to avoid prompting the user for permissions. But for a testing purposes, you can enable user notifications as soon as the application is ready. You may also want to set default foreground presentation options to display the notification in the foreground on iOS 10. On older iOS devices, make sure you background the app before sending the push.

Urban Airship Channel IDs

string channelId = UAirship.Shared.ChannelId;

The Channel ID is a unique identifier that ties together an application/device pair on a mobile device. The Channel ID is used to target pushes to specific devices using the Urban Airship API. Once a Channel ID is created, it will persist the application until it is either reinstalled, or its internal data is cleared.

Don’t worry if this value initially comes back as null on your app’s first run (or after clearing the application data), as the Channel ID will be created and persisted during registration.

Enabling User Notifications

UAirship.Shared.UserNotificationsEnabled = true;

The Urban Airship SDK makes a distinction between “user notifications”, which can be seen by the user, and other forms of push that allow you to send data to your app silently, or in the background. Enabling or disabling user notifications is a preference often best left up to the user, so by default, user notifications are disabled.

Listening for Events

OnChannelUpdated:

UAirship.Shared.OnChannelUpdated += (string channelId) => {
  Debug.Log ("Channel updated: " + channelId);
};

OnDeepLinkReceived:

UAirship.Shared.OnDeepLinkReceived += (string deeplink) => {
  Debug.Log ("Received deep link: " + deeplink);
};

OnPushReceived:

UAirship.Shared.OnPushReceived += (PushMessage message) => {
  Debug.Log ("Received push! " + message.Alert);
};

Available events:

OnChannelUpdated
Event when channel registration updates.
OnDeepLinkReceived
Event when a new deep link is available. The app should navigate to the proper page when the event is received.
OnPushReceived
Event when a push is received.

Addressing Devices

To help target specific devices or users for a notification, we have Tags, Named Users and Tag Groups.

Tags

// Add tag
UAirship.Shared.AddTag ("some-tag");

// Remove tag
UAirship.Shared.RemoveTag ("other-tag");

// Get tags
IEnumerable<string> tags = UAirship.Shared.Tags;

Tags allow you to attribute arbitrary metadata to a specific device. Common examples include favorites such as sports teams or news story categories.

Named Users

UAirship.Shared.NamedUserId = "coolNamedUserId";

Associating the channel with a Named User ID, will implicitly disassociate the channel from the previously associated Named User ID, if it existed.

Named Users allow you to associate multiple devices to a single user or profile that may be associated with more than one device, e.g., an end-user’s Android phone and tablet. A device can have only one Named User, and a single Named User should not be associated with more than 20 devices. Named Users provide the ability to directly set tags on them (see Tag Groups).

By default, Named Users cannot be associated from the device. In this case if the devices attempts a Named User association, the association will fail and the plugin will log an error. In order to change this setting, see the Settings documentation.

Tag Groups

Channel Tag Group Example:

UAirship.Shared.EditChannelTagGroups ()
     .AddTag ("loyalty", "silver-member")
     .RemoveTag ("loyalty", "bronze-member")
     .Apply ();

Named User Tag Group Example:

UAirship.Shared.EditNamedUserTagGroups ()
     .AddTag ("loyalty", "silver-member")
     .RemoveTag ("loyalty", "bronze-member")
     .Apply ();

Tag groups are configurable namespaces for organizing tags for the channel and Named User. Please view the Tag Groups documentation for more details. The Tag Group Walkthrough will guide you through the creation of your first Tag Group.

By default, Tag Groups cannot be modified from the device. In this case if a device attempts to modify Tag Groups, the modification will fail and the SDK will log an error. In order to change this setting, see the Settings documentation.

Custom Identifiers

Associating an identifier:

UAirship.Shared.AssociateIdentifier ("some key", "some identifier");

In addition to Named Users, tags, and Tag Groups, you can assign up to 20 custom identifiers to users. Identifiers that define additional ways of looking at a user – for example, iOS Vendor ID, iOS Advertising ID, Google Analytics CID, or any other identifier you deem significant – can be added to your users.

Custom identifiers will be visible in the Connect data stream. We recommend adding any IDs that you may want to be visible in Connect, even if Connect does not yet support the relevant integration. Unlike the other identifiers (e.g., tags), you cannot use custom identifiers to target your users.

Message Center

The default message center can be displayed at any time.

UAirship.Shared.DisplayMessageCenter ();

Urban Airship Message Center is a place in your app where you can display persistent rich messages, including HTML, video, etc. The messages are hosted by Urban Airship, and are typically displayed in standard inbox-style within your app.