Skip to content

Advanced

Creating notification groups

You can display notifications as groups in the notification center. Notifications that correspond to the same event can be grouped and displayed in a collapsed form. The collapsed notification group can be expanded again by the user, and individual notifications (each notification belonging to the group) can be executed separately.

Notification groups can be created by changing the group key to enabled and adding key values in the console > Notification > Push v4 > Register Push Campaign > Campaign Registration > Options > Group Key. After creating a group in the console, you can apply the notification group with groupId when sending local push and remote push notifications. When the group is applied, the notifications will be displayed collapsed by group as shown below.

Android
iOS
</tbody>

iOS media notification

By utilizing Apple's UserNotifications framework, you can add media files such as images and videos to notifications.

JPG(Image)
GIF(Image)
MP4(Video)

Operation process

The media notification feature operates using iOS's Notification Service Extension (hereinafter referred to as Extension).

The Notification Service Extension is a type of App Extension that allows you to modify the Payload before a Remote Notification is delivered to the user, enabling the use of processes (UI or functionality) from other apps without switching contexts. For more details, please refer to more.

  • Process of delivering Remote Notification after applying Extension

File aize and type limitations

There is a size limit when attaching media files, and detailed information can be found in UNNotificationAttachment.

Warning

We have discovered that when apps using AVAudioSession are running, such as Youtube and various mobile games (e.g., Summoners War, Be a Star, Chain Strike), sending audio received via push notifications can cause the main screen (Springboard) to reboot. This issue occurs regardless of the iOS version or device type, and it has been confirmed that a conflict occurs within the Apple system, separate from Hive.

On December 20, 2018, we inquired about this issue with Apple, and until a response is prepared, please discontinue the use of the audio transmission feature using media push.

Category Type Size Limit
Audio WAV, MP3, MP4(Audio) 5MB
Image JPG, JPEG, PNG, GIF 10MB
Video MP4, AVI 50MB
  • If a timeout occurs due to poor network conditions, the user will receive a regular Notification without media.
  • On very slow networks, downloads can take up to 10 minutes, so it is necessary to consider the network conditions in the area and use media with an appropriate size.

Implementation and utilization

To download media and reconstruct the Notification object for delivery to the user, several settings and additional source code are required.

Note

The Notification Service Extension cannot be included and distributed as part of a library or framework, so to use the Extension, you must proceed with the setup based on the guide provided by Hive.

Adding Extension

To use the media notification feature, you need to add a Notification Service Extension to your project. Instead of directly adding or overriding classes, add a new target to the project.

When you add a target, a template is automatically created.

<summary>Adding a target in Unity projects</summary>
In Unity Editor, the Hive SDK automatically performs the target addition and Info.plist creation process using the PostProcess feature. You only need to enable the media push option; no other manual steps are required.

1. In the Unity Editor menu bar, go to **Hive > Build project post process settings > iOS**
2. Enable **Push Media Contents**
<summary>Adding a target in non-Unity environments</summary>
1. In the project settings, click the **Add Target** button (the **+** button at the bottom left)
![noti_adv_1_plus-button](../img/noti_adv_1_plus-button.png){width="700px"}

2. Select **Notification Service Extension** and click **Next** <br>
(Since Xcode 8, you can add Notification Service Extension as a target in the project)
![noti_adv_1_plus-button](../img/noti_adv_2_template.png){width="700px"}

3. Enter the **Product Name**
![noti_adv_1_plus-button](../img/noti_adv_3_create.png){width="700px"}

4. When the popup appears, click **Activate** <br>
The Extension will be automatically embedded in the current project, and a Scheme for building will be added.
![noti_adv_1_plus-button](../img/noti_adv_4_activate.png){width="700px"}

5. In the **General** tab, check that the **Extension** has been added to the project
![noti_adv_1_plus-button](../img/noti_adv_5_general-frameworks.png){width="700px"}

6. Confirm that the **NotificationService** template class has been added to the project
![noti_adv_1_plus-button](../img/noti_adv_6_template-source.png){width="700px"}


Adding HIVEExtensions.framework

You can easily download media using the HIVEExtensions.framework provided by Hive.

The method to add HIVEExtensions.framework is as follows:

  1. The Hive SDK supports CocoaPods. If there is no Podfile in your project directory, run pod init. noti_adv_7-2_pod-init-terminal

    If you already have a Podfile, open the file and add the target 'NotificationServiceExtension (example target name)' do-end statement. noti_adv_7-2_pod-init-terminal

  2. Refer to the screenshot and write the pod statement. noti_adv_7-2_pod-init-terminal

  3. Close the Podfile and run pod install in your project directory. noti_adv_7-2_pod-init-terminal

  4. When you open NotificationSample (example project name).xcworkspace, you will see that the Pods project has been added as shown below. You can now import HIVEExtensions in both the NotificationSample and NotificationServiceExtension targets. noti_adv_7-2_pod-init-terminal

Applying the framework

Import the framework in the NotificationService.swift file as shown in the example. Implement the method provided in the template to call the methods provided by HIVEExtensions.framework and delete the original template code that was inside the method.

import HIVEExtensions

func didReceiveNotificationRequest(request: UNNotificationRequest, with contentHandler: (UNNotificationContent) -> Void) {
    HIVENotificationService.didReceive(request) { content in
        guard let content else { return }
        contentHandler(content)
    }
}

func serviceExtensionTimeWillExpire() {
    HIVENotificationService.serviceExtensionTimeWillExpire()
}
#import <HIVEExtensions/HIVEExtensions.h>

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
[HIVENotificationService didReceiveNotificationRequest:request withContentHandler:contentHandler];
}

- (void)serviceExtensionTimeWillExpire {
[HIVENotificationService serviceExtensionTimeWillExpire];
}

Precautions for application

Difference in sending and receiving time

After all tasks in the Extension are completed, the Notification is delivered to the user, which may result in a difference between the sending time and the receiving time, and the client will display the time based on when the server sent it.

For example, if a notification is sent at 15:00 and the download is completed at 15:05, the notification will be displayed as having arrived at 15:00.

Device capacity

The media received through push notifications is stored on the user's device and then exposed through the push, and the received media is stored in the device's internal cache data space, occupying the internal capacity of the user's device. The cache data space is automatically cleared by the OS if the internal storage capacity of the user's device is insufficient.

User's mobile data usage

The media received through push notifications will use the user's mobile data for downloading, and the download will proceed without the user's consent, which may incur data usage costs during the download.

In cases where audio/video files are delivered via push, check the user's network connection status before downloading. If the user is not connected to Wi-Fi, do not proceed with the download and instead display a push notification without media.

At this time, the type of media received through the push is confirmed by the extension specified at the end of the media URL, and only the extensions specified in the [File Size and Type Limit] section will be displayed correctly.

Received URL wifi LTE / 3G
http://xxx/notimovie.mp4 Media is always exposed after download Since it has the extension corresponding to a video file (mp4), it is exposed without media download
http://xxx/notimovie Media is always exposed after download It is not an audio/media file, so media is exposed after download
http://xxx/notisound.wav Media is always exposed after download Since it has the extension corresponding to an audio file (wav), it is exposed without media download
http://xxx/notiimage.jpg Media is always exposed after download It is not an audio/media file, so media is exposed after download

App transport security settings

Apple's default policy allows server communication performed by all apps to use https, and the URLs received through notifications are also affected by this policy. If you want to communicate using an Http domain, you need to set up an App Transport Security (ATS) exception.
Even if the Application has ATS exception handling, you must set up the ATS exception in the Extension to use http domains for the URLs transmitted via push notifications.

When media is not delivered in Unity

Hub connection error Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.com2us.hivesdk.normal.freefull.apple.global.ios.universal.NotificationServiceExtension" UserInfo={NSDebugDescription=connection to service named com.com2us.hivesdk.normal.freefull.apple.global.ios.universal.NotificationServiceExtension}

In Unity, there may be cases where media is not delivered while displaying error logs like the one above. In this case, please check whether both armv7 and arm64 values are included in the Architectures of the created Extension Target. noti_adv_7-2_pod-init-terminal

Push Action Buttons

Push action buttons are system buttons that appear when you long-press a push notification, as shown below. By exposing these additional buttons in push notifications, you can encourage user interaction.

With the Hive SDK, you can easily implement push action buttons with simple configuration.

Android iOS
noti_adv_14-1_push_action_mockup_ad noti_adv_14-2_push_action_mockup_ios
Note

No additional setup is required for push action buttons in the Android SDK. Refer to the Console Guide > Notification for details on using action button features. For the iOS SDK, you can implement push action buttons using either the 'basic implementation' or 'advanced implementation' methods.

Warning

When using push action buttons together with iOS Media Notification in the iOS SDK, the media notification feature may not work properly. When sending a push, use only one feature at a time—either 'media URL' or 'action push'. If both are used simultaneously, only the media thumbnail will be shown on receipt, and the expanded viewer will not appear when long-pressed.

Basic Implementation (iOS)

The Hive SDK provides a default set of push action buttons based on frequently used patterns, such as 'Confirm', 'Decline', etc. These built-in button combinations can be quickly applied, and you can also define and extend custom action button sets as needed. The default push action button sets are listed below.

* Confirm
* Close
* Confirm, Close
* Execute, Cancel
* Accept All, Close
* Claim Now, Close
* Purchase, Decline
* Sell, Decline
* Accept, Reject, Hold
| Category~(Category Identifier)~ | Button Name~(Action Identifier)~ |
|:---:|:----|
|Confirm~(INFO_CATEGORY)~|Confirm~(CONFIRM_ID)~|
|Close~(CLOSE_CATEGORY)~|Close~(CLOSE_ID)~|
|Confirm Selection~(CONFIRM_CATEGORY)~|Confirm~(CONFIRM_ID)~, Close~(CLOSE_ID)~|
|Execute~(EXECUTE_CATEGORY)~|Execute~(EXECUTE_ID)~, Cancel~(CANCEL_ID)~|
|Batch Accept~(ACCEPT_ALL_CATEGORY)~|Accept All~(ACCEPT_ALL_ID)~, Close~(CLOSE_ID)~|
|Immediate Claim~(ACCEPT_NOW_CATEGORY)~|Claim Now~(ACCEPT_NOW_ID)~, Close~(CLOSE_ID)~|
|Purchase Decision~(PURCHASE_CATEGORY)~|Purchase~(PURCHASE_ID)~, Decline~(DECLINE_ID)~|
|Sale Request~(SALE_CATEGORY)~|Sell~(SALE_ID)~, Decline~(DECLINE_ID)~|
|Decision~(ACCEPT_DECISION_CATEGORY)~|Accept~(ACCEPT_ID)~, Reject~(REJECT_ID)~, Hold~(HOLDING_ID)~|

No additional code is required to apply these push action button sets, but you must add a Notification Content Extension target to your project. Refer to the 'Push Action Button Set Application Guide' below for your development environment to add the target and activate push action buttons.

<summary>Applying Push Action Button Set in Unity</summary>
In Unity Editor, the Hive SDK's **PostProcess** feature automatically handles target addition and Info.plist creation. Simply check the option to use push action buttons; no other manual steps are required.

1. In the Unity Editor menu bar, go to **Hive > Build project post process settings > iOS**
2. Enable **Push Action Buttons**
<BR> The list shown when enabling the button previews the `categories` field from the *hive_push_actions.json* file used in [Advanced Implementation](#ios_1). If you proceed with the default implementation without this file, 'none' will be displayed.
<summary>Applying Push Action Button Set in Non-Unity Environments</summary>
After generating the Xcode project (.xcodeproj), follow these steps:

1. In project settings, click **Add Target**
2. Select **Notification Content Extension** and click **Next**
3. Enter the **Product Name** and assign the main game app target to **Embed in Application**
4. In the main game app target's **General** tab, confirm that the 'Product Name' has been added to the project
5. Check the automatically generated template class file~(NotificationContentViewController.swift)~ under the 'Product Name' path and enter as shown below
![noti_adv_15-noti_adv_15_push_action_addTarget_step5](../img/noti_adv_15_push_action_addTarget_step5.png)

Once you have applied the push action button set in your development environment, specify the actions when sending a push from the console.
When specifying actions, use the category and action identifiers from the detailed list above.

For more details on console settings, refer to the console guide.

Advanced Implementation (iOS)

Define the values for actions and categories in the hive_push_actions.json file. After defining, include the hive_push_actions.json file in your target and build the app. When the app runs, the Hive SDK automatically parses the file and registers the actions and categories in the notification center.

An example of the hive_push_actions.json file is shown below.

hive_push_actions.json Example
{
    "actions": {
        "ACCEPT_ALL_ID": { ... },
        "ACCEPT_ID": { ... },
        "ACCEPT_NOW_ID": { ... },
        "CANCEL_ID": { ... },
        "CLOSE_ID": { ... },
        "CONFIRM_ID": { ... },
        "DECLINE_ID": { ... },
        "EXECUTE_ID": { ... },
        "HOLDING_ID": { ... },
        "PURCHASE_ID": { ... },
        "REJECT_ID": { ... },
        "SALE_ID": { ... }
    },
    "categories": {
        "INFO_CATEGORY": ["CONFIRM_ID"],
        "CLOSE_CATEGORY": ["CLOSE_ID"],
        "CONFIRM_CATEGORY": ["CONFIRM_ID", "CLOSE_ID"],
        "EXECUTE_CATEGORY": ["EXECUTE_ID", "CANCEL_ID"],
        "ACCEPT_ALL_CATEGORY": ["ACCEPT_ALL_ID", "CLOSE_ID"],
        "ACCEPT_NOW_CATEGORY": ["ACCEPT_NOW_ID", "CLOSE_ID"],
        "PURCHASE_CATEGORY": ["PURCHASE_ID", "DECLINE_ID"],
        "SALE_CATEGORY": ["SALE_ID", "DECLINE_ID"]
    }
}

Notes for writing the file:

  • The maximum number of buttons per category (set) is 3.
  • The example above defines the default button sets. For custom action buttons, do not use duplicate identifiers; use unique, distinguishable strings.
  • Multi-language support follows the game language, and you can enter up to 16 languages supported by the Hive SDK. English ("en") is required as the default value for multi-language strings.
Note

Unity PostProcess is supported. If you add the hive_push_actions.json file to the same path as hive_config.xml in your Unity project, it will be automatically added to the app target when building the Xcode project.

Warning

After writing the file, add the keys from the "categories" field in the file to UNNotificationExtensionCategory in the Notification Content Extension's Info.plist.
In Unity, this is done automatically by analyzing the file.

FAQ

If custom action buttons do not appear even after including the file
  • Check that the file name is 'hive_push_actions.json'.
  • Make sure it is included in Copy Bundle Resources. noti_adv_15-1_push_action_faq1