여기에서는 플랫폼별로 푸시 알림을 사용하기 위해 필요한 설정 방법을 알아보겠습니다.
Android나 iOS에서 푸시를 설정하는 방법은 다음 문서를 참고하시기 바랍니다.
다음 API를 호출하여, NHN Cloud Push에 해당 사용자를 등록합니다. 푸시 동의 여부(enablePush), 광고성 푸시 동의 여부(enableAdPush), 야간 광고성 푸시 동의 여부(enableAdNightPush)값을 사용자로부터 받아, 다음 API를 호출해 등록을 완료합니다.
API
Supported Platforms ■ UNREAL_IOS ■ UNREAL_ANDROID
void RegisterPush(const FGamebasePushConfiguration& configuration, const FGamebaseErrorDelegate& onCallback);
void RegisterPush(const FGamebasePushConfiguration& configuration, const FGamebaseNotificationOptions& notificationOptions, const FGamebaseErrorDelegate& onCallback);
Example
void Sample::RegisterPush(bool pushEnabled, bool adAgreement, bool adAgreementNight)
{
FGamebasePushConfiguration configuration{ pushEnabled, adAgreement, adAgreementNight };
IGamebase::Get().GetPush().RegisterPush(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 의 생성자에 IGamebase::Get().GetPush().GetNotificationOptions() 호출 결과를 전달하면, 현재의 알림 옵션으로 초기화 된 오브젝트가 생성되므로, 필요한 값만 변경할 수 있습니다.
설정 가능한 값은 아래와 같습니다.
API | Parameter | Description |
---|---|---|
foregroundEnabled | bool | 앱이 포그라운드 상태일때의 알림 노출 여부 default: false |
badgeEnabled | bool | 배지 아이콘 사용 여부 default: true |
soundEnabled | bool | 알림음 사용 여부 default: true iOS Only |
priority | int32 | 알림 우선 순위. 아래 5가지 값을 설정할 수 있습니다. GamebaseNotificationPriority::Min : -2 GamebaseNotificationPriority::Low : -1 GamebaseNotificationPriority::Default : 0 GamebaseNotificationPriority::High : 1 GamebaseNotificationPriority::Max : 2 default: GamebaseNotificationPriority::High Android Only |
smallIconName | FString | 알림용 작은 아이콘 파일 이름. 설정하지 않을 경우 앱 아이콘이 사용됩니다. default: null Android Only |
soundFileName | FString | 알림음 파일 이름. 안드로이드 8.0 미만 OS 에서만 동작합니다. 'res/raw' 폴더의 mp3, wav 파일명을 지정하면 알림음이 변경됩니다. default: null Android Only |
Example
void Sample::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{ pushEnabled, adAgreement, adAgreementNight, displayLanguage };
FGamebaseNotificationOptions notificationOptions{ foregroundEnabled, badgeEnabled, soundEnabled, priority, smallIconName, soundFileName };
IGamebase::Get().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_IOS ■ UNREAL_ANDROID
FGamebaseNotificationOptionsPtr GetNotificationOptions();
Example
void Sample::GetNotificationOptions()
{
auto notificationOptions = IGamebase::Get().GetPush().GetNotificationOptions();
if (result.IsValid())
{
notificationOptions->foregroundEnabled = true;
notificationOptions->smallIconName = TEXT("notification_icon_name");
FGamebasePushConfiguration configuration;
IGamebase::Get().GetPush().RegisterPush(configuration, notificationOptions, FGamebaseErrorDelegate::CreateLambda([=](const FGamebaseError* error) { }));
}
else
{
UE_LOG(GamebaseTestResults, Display, TEXT("No GetNotificationOptions"));
}
}
사용자의 푸시 설정을 조회하려면 다음 API를 이용합니다. 콜백으로 받은 FGamebasePushTokenInfo 값으로 사용자 설정값을 얻을 수 있습니다.
API
Supported Platforms ■ UNREAL_IOS ■ UNREAL_ANDROID
void QueryTokenInfo(const FGamebasePushTokenInfoDelegate& onCallback);
// Legacy API
void QueryPush(const FGamebasePushConfigurationDelegate& onCallback);
Example
void Sample::QueryTokenInfo()
{
IGamebase::Get().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->adAgreement ? TEXT("true") : TEXT("false"),
tokenInfo->adAgreementNight ? 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 | 수신 동의 여부 |
sandbox | bool | sandbox 여부(iOS Only) |
Parameter | Values | Description |
---|---|---|
pushEnabled | bool | 알림 표시 동의 여부 |
adAgreement | bool | 광고성 알림 표시 동의 여부 |
adAgreementNight | bool | 야간 광고성 알림 표시 동의 여부 |
API
Supported Platforms ■ UNREAL_IOS
void SetSandboxMode(bool isSandbox);
Example
void Sample::SetSandboxMode(bool isSandbox)
{
IGamebase::Get().GetPush().SetSandboxMode(isSandbox);
}
Error | Error Code | Description |
---|---|---|
PUSH_EXTERNAL_LIBRARY_ERROR | 5101 | NHN Cloud Push 라이브러리 오류입니다. DetailCode를 확인하세요. |
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->message);
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->message);
}
}