[Caution]
If you use a 3rd party push plugin or module such as Unreal or Unity, it may affect the Gamebase push function.
This document describes the process of getting authentication information for APNS JWT required to deliver push notifications.
Import the following header file to the ViewController you want to implement a push API.
#import <Gamebase/Gamebase.h>
Call the following API to register the user for NHN Cloud Push.
Get the values of consent to receiving push (enablePush), consent to receiving advertisement push (enableAdPush), and consent to receiving night-time advertisement push (enableAdNightPush) from the user, and call the following API to complete the registration.
[Caution]
It is recommended that you always call the registerPush API after logging in, because it is not certain when the push token will expire.
- (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.
}
}];
}
When registering the user for the NHN Cloud Push, the notification option can be set using the TCGBNotificationOptions object.
- (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.
}
By turning on the SandboxMode, it can be registered so that the push will be sent with the APNS Sandbox.
- (void)didLoginSucceeded {
[TCGBPush setSandboxMode:YES];
[TCGBPush registerPushWithPushConfiguration:pushConfig completion:^(TCGBError *error) {
...
}];
}
Select iOS Sandbox as the Target from the Push menu and send push.
Retrieve the notification option value which was set when registering for the push notification.
- (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 | Expose the notification when the app is in the foreground default: NO |
badgeEnabled | YES or NO | Enable badge icon default: YES |
soundEnabled | YES or NO | Enable notification sound default: YES |
[Note]
foregroundEnabled option can be changed at runtime. badgeEnabled and soundEnabled options are applied only when registerPush API gets called for the first time, and any changes to them at runtime are not guaranteed.
To view the push settings of the user, the following API is used.
You can get the push info registered with the TCGBPushTokenInfo value which comes as callback.
- (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 type |
token | string | Token |
userId | string | User ID |
deviceCountryCode | string | Country code |
timezone | string | Standard timezone |
registeredDateTime | string | Token update time |
languageCode | string | Language settings |
sandbox | YES or NO | Checks if the token is registered in the sandbox environment |
agreement | TCGBPushAgreement | Opt in |
Parameter | Values | Description |
---|---|---|
pushEnabled | YES or NO | Opt in to display notifications |
ADAgreement | YES or NO | Opt in to display advertisement notifications |
ADAgreementNight | YES or NO | Opt in to display night advertisement notifications |
Error | Error Code | Description |
---|---|---|
TCGB_ERROR_PUSH_EXTERNAL_LIBRARY_ERROR | 5101 | Error in NHN Cloud Push library. Please check the error details. |
TCGB_ERROR_PUSH_ALREADY_IN_PROGRESS_ERROR | 5102 | Previous PUSH API call is not completed. Please call again after the previous push API callback is executed. |
TCGB_ERROR_PUSH_UNKNOWN_ERROR | 5999 | Unknown push error. Please upload the entire logs to Customer Center, and we'll respond ASAP. |
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]);
Error Code | Description |
---|---|
TCPushErrorNotInitialized | Not initialized |
TCPushErrorInvalidParameters | Parameter error |
TCPushErrorPermissionDenined | Permission not obtained |
TCPushErrorSystemFail | System alert registration failed |
TCPushErrorNetworkFail | Transmission on the network failed |
TCPushErrorServerFail | Server response failed |
TCPushErrorInvalidUrl | Invalid URL request |
TCPushErrorNetworkNotReachable | Network not connected |