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

This feature operates using the Notification Service Extension (hereinafter referred to as Extension) in iOS. 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 this feature, you need to add a Notification Service Extension to your project, and you should do this by adding a new target to the project instead of directly adding or overriding classes.

When you add a target to the project, a template is automatically created.

1. Click the target add button in the project settings (the red square at the bottom) noti_adv_1_plus-button

Select Notification Service Extension and click Next
(It has been possible to add Notification Service Extension as a target in the project since Xcode 8) noti_adv_1_plus-button

3. Enter the Product Name noti_adv_1_plus-button

4. When the popup below appears, click Activate
The Extension will be automatically included (Embedded) in the current project, and a Scheme for building will be added. noti_adv_1_plus-button

5. Check that the Extension has been added to the project in the General tab noti_adv_1_plus-button

6. A template class named NotificationService is added to the project noti_adv_1_plus-button

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 the project path, please run pod init. noti_adv_7-2_pod-init-terminal

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

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

  3. Close the Podfile and run pod install in the 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.m 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