入门
推送设置¶
用户将在应用安装后首次游戏时看到协议条款,并将进行同意流程以接收市场营销的广告推送。然而,对于那些不想接收推送通知的用户,您应该在游戏设置页面提供选择加入或退出服务的功能。
设置类型¶
应该可以选择是否接收所有通知、游戏通知、公告通知和夜间通知的推送通知。
| 所有通知 | 
 | 
| 游戏通知 | 
 | 
| 公告通知 | 
 | 
| 夜间通知 | 
 | 
推送设置策略¶
1. 为用户提供一个菜单,以激活或停用游戏中的推送服务。
-  推送设置的组成 
-  当推送通知设置更改时,您应该显示一个持续两秒的吐司弹出窗口。 
-  显示通知弹窗 - 当用户从韩国登录时
- 当所有通知、通知、夜间通知的设置更改时(对于游戏通知,不显示吐司弹窗)
 
-  吐司弹窗的文本 - 激活所有通知: [公司名称] 2016.05.01 您已选择接收所有通知。
- 停用公告通知: [公司名称] 2016.05.01 您已选择不接收公告通知。
- 激活夜间通知: [公司名称] 2016.05.01 您已选择接收夜间通知。
 
提供推送设置的通知文本。
如果用户在推送设置菜单中已启用推送,但仍未收到推送,请提供说明以检查用户在设备设置菜单中的通知设置。如果用户在设备设置中选择退出通知,则不会显示推送通知。
2. 使用 Hive SDK API 配置通过 Hive 控制台发送的通知设置。 
- Hive 控制台提供两种类型的推送通知:公告通知和夜间通知
- 两个通知选项的值必须设置为 Hive 服务器中设置的值。
- 当两个通知选项都更改时,您必须将更改传递到 Hive 服务器。
- 有关更多信息,请参见 发送远程推送。
3. 应用夜间通知政策。
夜间通知属于公告通知。请在实施夜间通知设置菜单时应用以下政策。
- 如果用户选择退出公告通知,夜间通知应自动停用。
- 在公告通知停用的情况下,夜间通知应无法激活。
- 即使用户选择退出公告通知,夜间通知也不应自动激活。
Note
配置夜间通知对于使用 Hive SDK 早于 v1.12.0 的游戏要求 国家代码对象 来检查用户从哪里玩游戏。
推送显示设置¶
推送通知通常在您的游戏应用未使用时显示。然而,使用 Hive SDK v4.9.0,推送服务可在应用被激活时也能显示。iOS 从 iOS 10 开始支持。
推送设置类
以下类显示在应用程序激活时是否发送推送消息。
推送设置回调
在调用推送设置 API 以检索请求结果时,实现以下回调。
设置是否在已激活的应用程序上接收推送消息
使用以下API,您可以设置在应用程序激活时是否接收推送消息。
API 参考: Push.setForegroundPush
using hive;    
    // 远程推送设置    
    Boolean useForegroundRemotePush = true;    
    // 本地推送设置    
    Boolean useForegroundLocalPush = false;    
    PushSetting pushSetting = new PushSetting(useForegroundRemotePush, useForegroundLocalPush);    
    Push.setForegroundPush (pushSetting, (ResultAPI result, PushSetting setting) => {    
         if (result.isSuccess()) {    
    // 调用成功    
    // 设置:通过API设置是否显示通知的结果    
         }    
});
#include "HivePush.h"
// 远程推送设置 
bool bUseForegroundRemotePush = true;
// 本地推送设置   
bool bUseForegroundLocalPush = false;
FHivePushSetting PushSetting(bUseForegroundRemotePush, bUseForegroundLocalPush);
FHivePush::SetForegroundPush(PushSetting, FHivePushOnPushSettingDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHivePushSetting& PushSetting) {
        if (Result.IsSuccess()) {
            // 调用成功    
    // 设置:通过API设置是否显示通知的结果 
        }
}));
API 参考: Push ::setForegroundPush
#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    // 远程推送设置    
    bool useForegroundRemotePush = true;    
    // 本地推送设置    
    bool useForegroundLocalPush = false;    
    PushSetting pushSetting(useRemote, useLocal);    
    Push::setForegroundPush(pushSetting, [=](ResultAPI const & result, PushSetting setting) {    
         if (result.isSuccess()) {    
             // call successful    
    // setting: Result of whether to display notifications set via API    
         }    
});
API 参考: Push.setForegroundPush
import com.hive.Push    
    import com.hive.ResultAPI    
    // 远程推送设置    
    val useForegroundRemotePush = true    
    // 本地推送设置    
    val useForegroundLocalPush = false    
    val pushSetting = Push.PushSetting(useForegroundRemotePush, useForegroundLocalPush)    
    Push.setForegroundPush(pushSetting, object: Push.PushSettingListener{    
         override fun onPushSetting(result: ResultAPI, pushSetting: Push.PushSetting?) {    
             if (result.isSuccess) {    
                 // 调用成功    
                 // pushSetting: 通过API设置的通知可见性结果    
             }    
         }    
})
API 参考: Push.INSTANCE .setForegroundPush
import com.hive.Push;    
    import com.hive.ResultAPI;    
    // 远程推送设置    
    boolean useForegroundRemotePush = true;    
    // 本地推送设置    
    boolean useForegroundLocalPush = false;    
    Push.PushSetting setting = new Push.PushSetting(useForegroundRemotePush, useForegroundLocalPush);    
    Push.INSTANCE.setForegroundPush(setting, (result, pushSetting) -> {    
         if (result.isSuccess()) {    
             // 调用成功    
             // pushSetting: 通过API设置的通知可见性结果    
         }    
});
API 参考: Swift
import HIVEService    
    let pushSetting = PushSetting()    
    // Remote push settings    
    pushSetting.useForegroundRemotePush = true    
    // Local push settings    
    pushSetting.useForegroundLocalPush = false    
    PushInterface.setForegroundPush(pushSetting) { result, setting in    
    if result.isSuccess() {    
    // call successful    
    // setting: Result of whether to display notifications set via API    
    }    
}
API 参考: Objective -C
#import <HIVEService/HIVEService-Swift.h>    
    HIVEPushSetting *pushSetting = [[HIVEPushSetting alloc] init];    
    // 远程推送设置    
    pushSetting.useForegroundRemotePush = YES;    
    // 本地推送设置    
    pushSetting.useForegroundLocalPush = NO;    
    [HIVEPush setForegroundPush: pushSetting handler: ^(HIVEResultAPI *result, HIVEPushSetting *setting) {    
         if ([result isSuccess]) {    
    // 调用成功    
    // setting: 通过API设置是否显示通知的结果    
         }    
}];
搜索是否在激活的应用上接收推送消息
使用以下API,您可以搜索应用程序激活时是否接收推送消息的状态。
API 参考: Push .getForegroundPush
API 参考: Push ::getForegroundPush
API 参考: Kotlin
API 参考: Push.INSTANCE .getForegroundPush
API 参考: PushInterface .getForegroundPush
API 参考: HIVEPush getForegroundPush
临时授权¶
Hive SDK v4.11.4 开始支持 iOS 12 的新功能,临时授权。
由于在同意Hive SDK的服务条款后,发送推送通知的协议弹窗不再显示,运行您的应用程序的用户默认会收到各种推送消息。通过临时授权,所有用户可以选择在推送消息或应用设置中接收推送通知。默认设置是推送消息不会发出声音或显示,直到用户手动选择接收推送通知,即使用户收到了消息。
 早于iOS 12的设备在初始化Hive SDK后,发送推送通知时会像往常一样显示协议弹窗。
请求显著推送权限¶
从 Hive SDK v4.16.2 (Android) 开始,如果游戏中需要,可以在发送显著推送通知时显示协议弹窗。要在发送显著推送通知时显示协议弹窗,请在用户设置是否同意发送推送通知之前,在 Push 类中调用 requestPushPermission() 方法。 对于 iOS,即使用户通过临时授权同意 Hive SDK 的服务条款,发送推送通知时也会显示协议弹窗,用户可以接收显著推送通知。 对于 Android,当目标 SDK 为 33 或更高版本时,在 Android 13 或更高版本的设备上会显示弹窗,当目标 SDK 低于 33 时,在调用 AuthV4.setup() 时会显示。
以下是发送推送通知时显示协议弹窗的示例代码。
API 参考: hive.Push.requestPushPermission
API 参考: Push::requestPushPermission
API 参考: Push.requestPushPermission
API 参考: HIVEPush:: requestPushPermission
推送多语言设置¶
| 语言 | 所有通知 | 游戏通知 | 公告通知 | 
|---|---|---|---|
| 韩语 | 모든 알림 | 게임 알림 | 공지 알림 | 
| 英语 | All Notifications | Game Notification | Announcement Notification | 
| 日语 | 全ての通知 | ゲーム通知 | お知らせ通知 | 
| 中文(简体) | 所有通知 | 游戏通知 | 公告通知 | 
| 中文(繁体) | 所有通知 | 遊戲通知 | 公告通知 | 
| 德语 | Alle Benachrichtigungen | Spiel-Benachrichtigung | Ankündigungen | 
| 俄语 | Все уведомления | Уведомления игры | Объявления | 
| 马来语 | Semua notifikasi | Notifikasi permainan | Notifikasi pengumuman | 
| 越南语 | Tất cả thông báo | Thông báo game | Thông báo tin tức | 
| 西班牙语 | Todas las notificaciones | Notificación del Juego | Notificación de Anuncio | 
| 意大利语 | Tutte le notifiche | Notifiche di gioco | Notifiche degli avvisi | 
| 印度尼西亚语 | Semua Notifikasi | Notifikasi Game | Notifikasi Pengumuman | 
| 泰语 | การแจ้งเตือนทั้งหมด | การแจ้งเตือนเกม | การแจ้งเตือนประกาศ | 
| 土耳其语 | Tüm Bildirimler | Oyun Bildirimi | Duyuru Bildirimi | 
| 葡萄牙语 | Todas as notificações | Notificação de Jogo | Notificação de Anúncios | 
| 法语 | Toutes les notifications | Notification de jeu | Notification d'annonce | 
| 阿拉伯语 | كل الإشعارات | إشعارات اللعبة | إشعارات الإخطار | 
推送通知和应用图标徽章¶
如果您在设备上收到通知,应用图标徽章会自动显示。应用图标徽章是一个计数器,显示应用图标右上角收到的通知数量。此徽章功能可以在设备设置或应用配置中打开/关闭。默认情况下,徽章的显示遵循以下操作系统政策。
- iOS- 应用图标徽章始终为1,无论新收到的通知数量如何。
- 当应用图标徽章变为0时,所有在通知中心堆积的通知将被移除。
- 应用图标徽章变为0的时间与Hive SDK的描述如下。- 应用的第一次运行
- 当应用通过点击其中一个通知返回前台时。
 
 
- Android- 当新通知到达时,应用图标徽章增加1。
- 当应用通过点击其中一个通知运行应用或通过其他方式返回前台时,徽章重置为0。
- 只有被点击的通知会从通知中心移除。
 







