[注意]
Unreal、Unityなど3rd partyプッシュプラグインまたはモジュールを使用する場合は、 Gamebaseプッシュ機能に影響を与える可能性があります。
ここではPush通知の送信に必要なAPNS JWT認証情報を取得するプロセスを説明します。
Push APIを設計するViewControllerに次のヘッダーファイルを持ってきます。
#import <Gamebase/Gamebase.h>
次のAPIを呼び出して、NHN Cloud Pushに該当ユーザーを登録します。
プッシュ受信同意有無(TCGBPushConfiguration)をユーザーから取得し、次のAPIを呼び出して登録を完了します。
[注意]
プッシュトークンがいつ有効期限切れになるかわからないため、ログイン後は常にregisterPush APIを呼び出すことを推奨します。
+ (void)registerPushWithPushConfiguration:(TCGBPushConfiguration *)configuration
completion:(nullable void(^)(TCGBError * _Nullable error))completion;
Parameter | Mandatory(M) / Optional(O) |
Values | Description |
---|---|---|---|
pushEnabled | M | BOOL | プッシュ同意有無 |
ADAgreement | M | BOOL | 広告性プッシュ同意有無 |
ADAgreementNight | M | BOOL | 夜間広告性プッシュ同意有無 |
alwaysAllowTokenRegistration | O | BOOL | ユーザーがプッシュ権限を拒否してもトークンを登録するかどうか YESに設定した場合は、プッシュ権限を取得できなくてもトークンを登録します。 default: NO |
- (void)didLoginSucceeded {
BOOL enablePush;
BOOL enableAdPush;
BOOL enableAdNightPush;
BOOL alwaysAllowTokenRegistration;
// You should receive the above values to the logged-in user.
TCGBPushConfiguration* pushConfig = [TCGBPushConfiguration pushConfigurationWithPushEnable:enablePush
ADAgreement:enableAdPush
ADAgreementNight:enableAdNightPush
alwaysAllowTokenRegistration:alwaysAllowTokenRegistration];
[TCGBPush registerPushWithPushConfiguration:pushConfig completion:^(TCGBError* error) {
if (error != nil) {
// To Register Push Failed.
}
}];
}
NHN Cloud Pushにユーザーを登録する時、TCGBNotificationOptionsオブジェクトで通知オプションの設定が可能です。
フォアグラウンドプッシュ有無(foregroundEnabled)、バッジ使用有無(badgeEnabled)、通知音使用有無(soundEnabled)値をユーザーから取得し、次のAPIを呼び出して通知オプションの設定が可能です。
+ (void)registerPushWithPushConfiguration:(TCGBPushConfiguration *)configuration
notificationOptions:(nullable TCGBNotificationOptions *)notificationOptions
completion:(nullable void(^)(TCGBError * _Nullable error))completion;
Parameter | Mandatory(M) / Optional(O) |
Values | Description |
---|---|---|---|
foregroundEnabled | M | BOOL | アプリがフォアグラウンド状態の時に通知を表示するかどうか default: NO |
badgeEnabled | M | BOOL | バッジアイコンの使用有無 default: YES |
soundEnabled | M | BOOL | 通知音の使用有無 default: YES |
- (void)didLoginSucceeded {
BOOL enablePush;
BOOL enableAdPush;
BOOL enableAdNightPush;
BOOL alwaysAllowTokenRegistration;
BOOL foregroundEnabled;
BOOL badgeEnabled;
BOOL soundEnabled;
// You should receive the above values to the logged-in user.
TCGBPushConfiguration *pushConfig = [TCGBPushConfiguration pushConfigurationWithPushEnable:enablePush
ADAgreement:enableAdPush
ADAgreementNight:enableAdNightPush
alwaysAllowTokenRegistration:alwaysAllowTokenRegistration];
TCGBNotificationOptions *options = [TCGBNotificationOptions notificationOptionsWithForegroundEnabled:foregroundEnabled
badgeEnabled:badgeEnabled
soundEnabled:soundEnabled];
[TCGBPush registerPushWithPushConfiguration:pushConfig notificationOptions:options completion:^(TCGBError* error) {
if (error != nil) {
// To Register Push Failed.
}
}];
// You should receive the above values to the logged-in user.
}
SandboxModeをオンにすると、APNS SandboxでPushを送信するように登録できます。
- (void)didLoginSucceeded {
[TCGBPush setSandboxMode:YES];
[TCGBPush registerPushWithPushConfiguration:pushConfig completion:^(TCGBError *error) {
...
}];
}
Pushメニューの対象からiOS Sandboxを選択した後に送信します。
プッシュを登録する時に設定した通知オプション値を取得します。
- (void)didLoginSucceeded {
TCGBNotificationOptions *options = [TCGBPush notificationOptions];
if (options == nil) {
// You need to login and call the registerPush API first.
}
}
[参考]
foregroundEnabledオプションはランタイムの時に変更が可能です。 badgeEnabled、soundEnabledオプションは、registerPush APIを初めて呼び出した時にのみ反映され、ランタイムの時の変更は保障されません。
ユーザーのプッシュ設定を照会するために、次のAPIを利用します。 コールバックで来るTCGBPushTokenInfo値で登録したプッシュ情報を取得できます。
- (void)didLoginSucceeded {
[TCGBPush queryTokenInfoWithCompletion:^(TCGBPushTokenInfo *tokenInfo, TCGBError *error) {
if ([TCGBGamebase isSuccessWithError:error] == NO) {
// To Request Push Token Info Failed.
}
NSString *pushType = tokenInfo.pushType;
NSString *token = tokenInfo.token;
...
// You can handle these variables.
}];
}
Parameter | Values | Description |
---|---|---|
pushType | string | Pushトークンタイプ |
token | string | トークン |
userId | string | ユーザーID |
deviceCountryCode | string | 国コード |
timezone | string | 標準時間帯 |
registeredDateTime | string | トークンアップデート時間 |
languageCode | string | 言語設定 |
sandbox | YES or NO | サンドボックス環境で登録されたトークンなのかを確認 |
agreement | TCGBPushAgreement | 受信同意有無 |
Parameter | Values | Description |
---|---|---|
pushEnabled | YES or NO | 通知表示同意有無 |
ADAgreement | YES or NO | 広告性通知表示同意有無 |
ADAgreementNight | YES or NO | 夜間広告性通知表示同意有無 |
Error | Error Code | Description |
---|---|---|
TCGB_ERROR_PUSH_EXTERNAL_LIBRARY_ERROR | 5101 | NHN Cloud Pushライブラリエラーです。 詳細エラーをご確認ください。 |
TCGB_ERROR_PUSH_ALREADY_IN_PROGRESS_ERROR | 5102 | 前回のPush APIの呼び出しが完了していません。 前回のPush APIのコールバックが実行された後、もう一度呼び出してください。 |
TCGB_ERROR_PUSH_UNKNOWN_ERROR | 5999 | 定義されていないPushエラーです。 ログ全体をカスタマーセンターにアップロードしてください。なるべく早くお答えいたします。 |
TCGB_ERROR_PUSH_EXTERNAL_LIBRARY_ERROR
TCGBError *tcgbError = error; // TCGBError object via callback
NSInteger detailErrorCode = [error detailErrorCode];
NSString *detailErrorMessage = [error detailErrorMessage];
// If you use **description** method, you can get entire information of this object by JSON Format
NSLog(@"TCGBError:%@", [tcgbError description]);
エラーコード | 説明 |
---|---|
NHNCloudPushErrorUnknown | 不明 |
NHNCloudPushErrorNotInitialized | 初期化されていない |
NHNCloudPushErrorUserInvalid | ユーザーIDが未設定 |
NHNCloudPushErrorPermissionDenied | 権限の取得に失敗 |
NHNCloudPushErrorSystemFailed | システムによる失敗 |
NHNCloudPushErrorTokenInvalid | トークン値がないか無効 |
NHNCloudPushErrorAlreadyInProgress | すでに進行中 |
NHNCloudPushErrorParameterInvalid | 引数エラー |
NHNCloudPushErrorNotSupported | サポートしていない機能 |
NHNCloudPushErrorClientFailed | サーバーエラー |