[注意]
Unreal、Unityなど3rd partyプッシュプラグインまたはモジュールを使用する場合は、 Gamebaseプッシュ機能に影響を与える可能性があります。
ここではPush通知の送信に必要なApple開発者認証書を作成する過程について説明します。
Push APIを設計するViewControllerに次のヘッダーファイルを持ってきます。
#import <Gamebase/Gamebase.h>
次のAPIを呼び出して、 NHN Cloud Pushに該当ユーザーを登録します。
プッシュ同意有無(enablePush)、広告性プッシュ同意有無(enableAdPush)、夜間広告性プッシュ同意有無(enableAdNightPush)値をユーザーから取得し、次のAPIを呼び出して登録を完了します。
[注意]
プッシュトークンがいつ有効期限切れになるかわからないため、ログイン後は常にregisterPush APIを呼び出すことを推奨します。
- (void)didLoginSucceeded {
BOOL enablePush;
BOOL enableAdPush;
BOOL enableAdNightPush;
// You should receive the above values to the logged-in user.
TCGBPushConfiguration* pushConfig = [TCGBPushConfiguration pushConfigurationWithPushEnable:enablePush ADAgreement:enableAdPush ADAgreementNight:enableAdNightPush];
[TCGBPush registerPushWithPushConfiguration:pushConfig completion:^(TCGBError* error) {
if (error != nil) {
// To Register Push Failed.
}
}];
}
NHN Cloud Pushにユーザーを登録する時、TCGBNotificationOptionsオブジェクトで通知オプションの設定が可能です。
- (void)didLoginSucceeded {
BOOL enablePush;
BOOL enableAdPush;
BOOL enableAdNightPush;
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];
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.
}
}
Parameter | Values | Description |
---|---|---|
foregroundEnabled | YES or NO | アプリがフォアグラウンド状態の時の通知表示有無 default: NO |
badgeEnabled | YES or NO | バッジアイコン使用有無 default: YES |
soundEnabled | YES or NO | 通知音使用有無 default: YES |
[参考]
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ライブラリーエラーです。 DetailCodeを確認してください。 |
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; // Callbackで返ってきたTCGBErrorのインスタンス
NSError *moduleError = [tcgbError.userInfo objectForKey:NSUnderlyingErrorKey]; // 外部ライブラリーで発生したエラーの客体
NSInteger moduleErrorCode = moduleError.code;
NSString *moduleErrorMessage = moduleError.message;
// 次の[tcgbError description]を呼び出すことで、json formatの全体のエラー情報を取得できます。
NSLog(@"TCGBError:%@", [tcgbError description]);
エラーコード | 説明 |
---|---|
TCPushErrorNotInitialized | 初期化されていない |
TCPushErrorInvalidParameters | パラメータエラー |
TCPushErrorPermissionDenined | 権限未取得 |
TCPushErrorSystemFail | システム通知登録失敗 |
TCPushErrorNetworkFail | ネットワーク送受信失敗 |
TCPushErrorServerFail | サーバーレスポンス失敗 |
TCPushErrorInvalidUrl | 無効なURLリクエスト |
TCPushErrorNetworkNotReachable | ネットワーク未接続 |