여기에서는 플랫폼별로 푸시 알림을 사용하기 위해 필요한 설정 방법을 알아보겠습니다.
Android나 iOS에서 푸시를 설정하는 방법은 다음 문서를 참고하시기 바랍니다.
[주의]
외부 플러그인에서 푸시 관련 처리가 있는 경우, Gamebase 푸시 기능이 정상적으로 동작하지 않을 수 있습니다.
다음 API를 호출하여, NHN Cloud Push에 해당 사용자를 등록합니다. 푸시 동의 여부(enablePush), 광고성 푸시 동의 여부(enableAdPush), 야간 광고성 푸시 동의 여부(enableAdNightPush)값을 사용자로부터 받아, 다음 API를 호출해 등록을 완료합니다.
[주의]
UserID 마다 푸시 설정이 다를 수 있고, 푸시 토큰이 만료되는 경우도 발생할 수 있으므로 로그인 이후에는 매번 RegisterPush API를 호출할 것을 권장합니다.
API
Supported Platforms ■ UNREAL_ANDROID ■ UNREAL_IOS
void RegisterPush(const FGamebasePushConfiguration& Configuration, const FGamebaseErrorDelegate& Callback);
void RegisterPush(const FGamebasePushConfiguration& Configuration, const FGamebaseNotificationOptions& NotificationOptions, const FGamebaseErrorDelegate& Callback);
Parameter | Mandatory(M) / Optional(O) |
Values | Description |
---|---|---|---|
bPushEnabled | M | bool | 푸시 동의 여부 |
bAdAgreement | M | bool | 광고성 푸시 동의 여부 |
bAdAgreementNight | M | bool | 야간 광고성 푸시 동의 여부 |
bRequestNotificationPermission | O | bool | Android 13 이상의 OS에서 RegisterPush API를 호출했을 때 푸시 권한 요청 팝업 자동 출력 여부 default: true Android에 한함 |
bAlwaysAllowTokenRegistration | O | bool | 사용자가 푸시 권한을 거부해도 토큰을 등록할지 여부 true로 설정할 경우 푸시 권한을 획득하지 못하더라도 토큰을 등록합니다. default: false iOS에 한함 |
Example
void USample::RegisterPush(bool pushEnabled, bool adAgreement, bool adAgreementNight)
{
FGamebasePushConfiguration Configuration;
Configuration.bPushEnabled = pushEnabled;
Configuration.bAdAgreement = adAgreement;
Configuration.bAdAgreementNight = adAgreementNight;
Configuration.bRequestNotificationPermission = bRequestNotificationPermission;
Configuration.bAlwaysAllowTokenRegistration = bAlwaysAllowTokenRegistration;
UGamebaseSubsystem* Subsystem = UGameInstance::GetSubsystem<UGamebaseSubsystem>(GetGameInstance());
Subsystem->GetPush()->RegisterPush(Configuration, FGamebasePushConfigurationDelegate::CreateLambda([](const FGamebaseError* Error)
{
if (Gamebase::IsSuccess(Error))
{
UE_LOG(GamebaseTestResults, Display, TEXT("RegisterPush succeeded"));
}
else
{
UE_LOG(GamebaseTestResults, Display, TEXT("RegisterPush failed. (Error: %d)"), Error->Code);
}
}));
}
RegisterPush API 호출 시 FGamebaseNotificationOptions 인자를 추가하여 알림 옵션을 설정할 수 있습니다.
FGamebaseNotificationOptions 의 생성자에 GamebaseSubsystem->GetPush()->GetNotificationOptions() 호출 결과를 전달하면 현재의 알림 옵션으로 초기화된 오브젝트가 생성되므로 필요한 값만 변경할 수 있습니다.
설정 가능한 값은 아래와 같습니다.
API | Parameter | Description |
---|---|---|
bForegroundEnabled | bool | 앱이 포그라운드 상태일 때의 알림 노출 여부 default: false |
bBadgeEnabled | bool | 배지 아이콘 사용 여부 default: true |
bSoundEnabled | bool | 알림음 사용 여부 default: true iOS에 한함 |
Priority | int32 | 알림 우선 순위. 아래 5가지 값을 설정할 수 있습니다. GamebaseNotificationPriority::Min : -2 GamebaseNotificationPriority::Low : -1 GamebaseNotificationPriority::Default : 0 GamebaseNotificationPriority::High : 1 GamebaseNotificationPriority::Max : 2 default: GamebaseNotificationPriority::High Android에 한함 |
SmallIconName | FString | 알림용 작은 아이콘 파일 이름. 설정하지 않을 경우 앱 아이콘이 사용됩니다. default: null Android에 한함 |
SoundFileName | FString | 알림음 파일 이름. Android 8.0 미만 OS에서만 동작합니다. 'res/raw' 폴더의 mp3, wav 파일명을 지정하면 알림음이 변경됩니다. default: null Android에 한함 |
Example
void USample::RegisterPushWithOption(bool pushEnabled, bool adAgreement, bool adAgreementNight, const FString& displayLanguage, bool foregroundEnabled, bool badgeEnabled, bool soundEnabled, int32 priority, const FString& smallIconName, const FString& soundFileName)
{
FGamebasePushConfiguration Configuration;
Configuration.bPushEnabled = pushEnabled;
Configuration.bAdAgreement = adAgreement;
Configuration.bAdAgreementNight = adAgreementNight;
Configuration.bRequestNotificationPermission = bRequestNotificationPermission;
Configuration.bAlwaysAllowTokenRegistration = bAlwaysAllowTokenRegistration;
FGamebaseNotificationOptions NotificationOptions;
NotificationOptions.bForegroundEnabled = bForegroundEnabled;
NotificationOptions.bBadgeEnabled = bBadgeEnabled;
NotificationOptions.bSoundEnabled = bSoundEnabled;
NotificationOptions.Priority = Priority;
NotificationOptions.SmallIconName = SmallIconName;
NotificationOptions.SoundFileName = SoundFileName;
UGamebaseSubsystem* Subsystem = UGameInstance::GetSubsystem<UGamebaseSubsystem>(GetGameInstance());
Subsystem->GetPush()->RegisterPush(Configuration, NotificationOptions, FGamebaseErrorDelegate::CreateLambda([=](const FGamebaseError* Error)
{
if (Gamebase::IsSuccess(Error))
{
UE_LOG(GamebaseTestResults, Display, TEXT("RegisterPush succeeded"));
}
else
{
// Check the Error code and handle the Error appropriately.
UE_LOG(GamebaseTestResults, Display, TEXT("RegisterPush failed. (Error: %d)"), Error->Code);
}
}));
}
푸시를 등록할 때 기존에 설정했던 알림 옵션값을 가져옵니다.
API
Supported Platforms
■ UNREAL_ANDROID ■ UNREAL_IOS
FGamebaseNotificationOptionsPtr GetNotificationOptions();
Example
void USample::GetNotificationOptions()
{
auto NotificationOptions = UGamebaseSubsystem* Subsystem = UGameInstance::GetSubsystem<UGamebaseSubsystem>(GetGameInstance());
Subsystem->GetPush()->GetNotificationOptions();
if (result.IsValid())
{
NotificationOptions->ForegroundEnabled = true;
NotificationOptions->SmallIconName = TEXT("notification_icon_name");
FGamebasePushConfiguration Configuration;
UGamebaseSubsystem* Subsystem = UGameInstance::GetSubsystem<UGamebaseSubsystem>(GetGameInstance());
Subsystem->GetPush()->RegisterPush(Configuration, NotificationOptions, FGamebaseErrorDelegate::CreateLambda([=](const FGamebaseError* Error) { }));
}
else
{
UE_LOG(GamebaseTestResults, Display, TEXT("No GetNotificationOptions"));
}
}
사용자의 푸시 설정을 조회하려면 다음 API를 이용합니다. 콜백으로 받은 FGamebasePushTokenInfo 값으로 사용자 설정값을 얻을 수 있습니다.
API
Supported Platforms ■ UNREAL_ANDROID ■ UNREAL_IOS
void QueryTokenInfo(const FGamebasePushTokenInfoDelegate& Callback);
// Legacy API
void QueryPush(const FGamebasePushConfigurationDelegate& Callback);
Example
void USample::QueryTokenInfo()
{
UGamebaseSubsystem* Subsystem = UGameInstance::GetSubsystem<UGamebaseSubsystem>(GetGameInstance());
Subsystem->GetPush()->QueryTokenInfo(FGamebasePushTokenInfoDelegate::CreateLambda([=](const FGamebasePushTokenInfo* TokenInfo, const FGamebaseError* Error)
{
if (Gamebase::IsSuccess(Error))
{
UE_LOG(GamebaseTestResults, Display, TEXT("QueryTokenInfo succeeded. (pushEnabled= %s, adAgreement= %s, adAgreementNight= %s, TokenInfo= %s)"),
TokenInfo->PushEnabled ? TEXT("true") : TEXT("false"),
TokenInfo->bAdAgreement ? TEXT("true") : TEXT("false"),
TokenInfo->bAdAgreementNight ? TEXT("true") : TEXT("false"),
*TokenInfo->Token);
}
else
{
UE_LOG(GamebaseTestResults, Display, TEXT("QueryTokenInfo failed. (Error: %d)"), Error->Code);
}
}));
}
Parameter | Values | Description |
---|---|---|
PushType | FString | Push 토큰 타입 |
Token | FString | 토큰 |
UserId | FString | 사용자 아이디 |
DeviceCountryCode | FString | 국가 코드 |
Timezone | FString | 표준시간대 |
RegisteredDateTime | FString | 토큰 업데이트 시간 |
LanguageCode | FString | 언어 설정 |
Agreement | FGamebasePushAgreement | 수신 동의 여부 |
bSandbox | bool | sandbox 여부(iOS에 한함) |
Parameter | Values | Description |
---|---|---|
bPushEnabled | bool | 알림 표시 동의 여부 |
bAdAgreement | bool | 광고성 알림 표시 동의 여부 |
bAdAgreementNight | bool | 야간 광고성 알림 표시 동의 여부 |
API
Supported Platforms ■ UNREAL_IOS
void SetSandboxMode(bool isSandbox);
Example
void USample::SetSandboxMode(bool isSandbox)
{
UGamebaseSubsystem* Subsystem = UGameInstance::GetSubsystem<UGamebaseSubsystem>(GetGameInstance());
Subsystem->GetPush()->SetSandboxMode(isSandbox);
}
Error | Error Code | Description |
---|---|---|
PUSH_EXTERNAL_LIBRARY_ERROR | 5101 | NHN Cloud Push 라이브러리 오류입니다. 상세 오류를 확인하십시오. |
PUSH_ALREADY_IN_PROGRESS_ERROR | 5102 | 이전 푸시 API 호출이 완료되지 않았습니다. 이전 푸시 API의 콜백이 실행된 이후에 다시 호출하세요. |
PUSH_UNKNOWN_ERROR | 5999 | 정의되지 않은 푸시 오류입니다. 전체 로그를 고객 센터에 올려 주시면 가능한 한 빠르게 답변 드리겠습니다. |
PUSH_EXTERNAL_LIBRARY_ERROR
GamebaseError* gamebaseError = Error; // GamebaseError object via callback
if (Gamebase::IsSuccess(Error))
{
// succeeded
}
else
{
UE_LOG(GamebaseTestResults, Display, TEXT("code: %d, message: %s"), Error->Code, *Error->Messsage);
GamebaseInnerError* moduleError = gamebaseError.Error; // GamebaseError.Error object from external module
if (moduleError.Code != GamebaseErrorCode::SUCCESS)
{
UE_LOG(GamebaseTestResults, Display, TEXT("moduleErrorCode: %d, moduleErrorMessage: %s"), moduleerror->Code, *moduleerror->Messsage);
}
}