TCGBGamebase Class Reference

Inherits from NSObject
Declared in TCGBGamebase.h

Overview

The TCGBGamebase class is core of TCGB service.

Initialization

+ initializeWithConfiguration:completion:

This method initialize TCGBGamebase with TCGBConfiguration instance. InitializeCompletion return launching datas when TCGBGamebase has initialized and has completed getting launching informations from server.

+ (void)initializeWithConfiguration:(TCGBConfiguration *)configuration completion:(InitializeCompletion)completion

Parameters

configuration

A parameter that were set appId, appVersion, zoneType and etc.

completion

A completion that is called after initializing TCGBGamebase completed.

Discussion

You must call this method first, after the app has launched.

Usage Example

- (void)onButtonInitialize {
    [TCGBGamebase setDebugMode:YES];
    TCGBConfiguration* config = [TCGBConfiguration configurationWithAppID:@"your app(project) ID" appVersion:@"your app version"];
    [TCGBGamebase initializeWithConfiguration:config completion:^(LaunchingInfo launchingData, TCGBError *error) {
        if ([TCGBGamebase isSuccessWithError:error] == YES) {
            NSLog(@"TCGBGamebase initialization is succeeded");
            // Check status of you app.
            // If status of app is maintenance or terminated service or etc, you must blocking UI and you should make user cannot log in your service.
            // You can use [TCGBLaunching launchingStatus] method to check status of your app.
        }
        else {
            NSLog(@"TCGBGamebase initialization is failed with error:[%@]", [error description]);
        }
    }];
}

Declared In

TCGBGamebase.h

+ initializeWithConfiguration:launchOptions:completion:

This method initialize TCGBGamebase with TCGBConfiguration instance. InitializeCompletion return launching datas when TCGBGamebase has initialized and has completed getting launching informations from server.

+ (void)initializeWithConfiguration:(TCGBConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions completion:(InitializeCompletion)completion

Parameters

configuration

A parameter that were set appId, appVersion, zoneType and etc.

launchOptions

An extra launch options when application needs to be customized initialization.

completion

A completion that is called after initializing TCGBGamebase completed.

Discussion

You must call this method first, after the app has launched.

Declared In

TCGBGamebase.h

Environment Setting & Getting

+ setDebugMode:

Method that setting TCGBGamebase to debug mode. Debug mode can print logs that has debug, info and verbose log level on console app.

+ (void)setDebugMode:(BOOL)debugMode

Parameters

debugMode

Boolean value that whether use debug mode or not.

Discussion

You should call this method before calling initializeWithConfiguration:launchOptions:completion: method.

Usage Example

 - (void)onButtonInitialize {
    [TCGBGamebase setDebugMode:YES];
    TCGBConfiguration* config = [TCGBConfiguration configurationWithAppID:@"your app(project) ID" appVersion:@"your app version"];
    [TCGBGamebase initializeWithConfiguration:config completion:^(LaunchingInfo launchingData, TCGBError *error) {
        if ([TCGBGamebase isSuccessWithError:error] == YES) {
            NSLog(@"TCGBGamebase initialization is succeeded");
            // Check status of you app.
            // If status of app is maintenance or terminated service or etc, you must blocking UI and you should make user cannot log in your service.
            // You can use [TCGBLaunching launchingStatus] method to check status of your app.
        }
        else {
            NSLog(@"TCGBGamebase initialization is failed with error:[%@]", [error description]);
        }
    }];
 }

See Also

Declared In

TCGBGamebase.h

+ isDebugMode

Method that got boolean value whether current SDK is running with debug mode or not.

+ (BOOL)isDebugMode

Return Value

Boolean value that current SDK is running with debug mode or not.

Discussion

Usage Example

-(void)onButtonIsDebugMode {
    BOOL isDebugMode = [TCGBGamebase isDebugMode];
    NSLog(@"Debug Mode is %@", isDebugMode ? @"on":@"off");
}

See Also

Declared In

TCGBGamebase.h

+ SDKVersion

Method that got SDK version of client

+ (NSString *)SDKVersion

Return Value

String value that got client sdk version.

Discussion

Usage Example

- (void)onButtonGetSDKVersion {
    NSString* version = [TCGBGamebase SDKVersion];
    NSLog(@"Client SDK Version = %@", version];
}

Declared In

TCGBGamebase.h

+ appID

Method that got ‘Projet ID (app ID)’ is set by initialize TCGBGamebase.

+ (NSString *)appID

Return Value

String value that got app id (project id).

Discussion

‘Project ID (app ID)’ is indicated on Toast Cloud Console Project List Page.

Usage Example

- (void)onButtonGeTCGBPID {
    NSString* appID = [TCGBGamebase appID];
    NSLog(@"App ID = %@", appID);
}

Declared In

TCGBGamebase.h

+ userID

Method that got an UserID that identify each user in Platform.

+ (NSString *)userID

Return Value

String value that got userID.

Discussion

You can get this after login has succeeded.

Usage Example

- (void)onButtonGetUserID {
    NSString* userID = [TCGBGamebase userID];
    NSLog(@"User ID = %@", userID];
}

Declared In

TCGBGamebase.h

+ accessToken

Method that got an access token is taken from TCGB Platform server.

+ (NSString *)accessToken

Return Value

String value that got TCGB Access Token.

Discussion

You can get htis after login has succeeded. This value will be removed by logout, withdrawal and will be expired 15 day after last logged in.

Usage Example

- (void)onButtonAccessToken {
    NSString* TCGBAccessToken = [TCGBGamebase accessToken];
    NSLog(@"User ID = %@", TCGBAccessToken];
}

Declared In

TCGBGamebase.h

+ isSandbox

Return whether this project is sandbox mode or not.

+ (BOOL)isSandbox

Return Value

Boolean value whether this project is sandbox mode.

Declared In

TCGBGamebase.h

+ isSuccessWithError:

Method that distinguished the error object is whether succeeded or failed.

+ (BOOL)isSuccessWithError:(TCGBError *)error

Parameters

error

Object for TCGBError class what distinguished is whether succeeded or not.

Return Value

Boolean value that the TCGBError object is whether succeeded of failed.

Discussion

Usage Example

- (void)onButtonSuccessOfFail {
    [TCGBGamebase logoutWithCompletion:^(TCGBError *error) {
        BOOL isSuccess = [TCGBGamebase isSuccessWithError:error];
        if (isSuccess) {
            NSLog(@"logout is Success");
        }
        else {
            NSLog(@"logout is Fail");
        }
    }
}

Declared In

TCGBGamebase.h

Login API

+ loginWithType:viewController:completion:

Try to login with type of ID Provider. If after succeeded, completion returns TCGB Auth informations include authToken, userID.

+ (void)loginWithType:(NSString *)type viewController:(UIViewController *)viewController completion:(LoginCompletion)completion

Parameters

type

String value of IDPType name (guest, facebook, payco, iosgamecenter).

viewController

UIViewController object that present login view controller.

completion

callback that returned whether login success or fail and return TCGBAuthToken.

Discussion

TCGBGamebase has loginForLastLoggedInProviderWithCompletion method known as Auto-Login. So before you try to login, you should try to login with loginForLastLoggedInProviderWithCompletion: method. If it is failed, you can try to login with loginWithType:viewController:completion: method

Usage Example

- (void)onButtonLogin {
    NSString* idpType = @"facebook";
    UIViewController* topViewController = nil;

    [TCGBGamebase loginForLastLoggedInProviderWithCompletion:^(TCGBAuthToken *authToken, TCGBError *error){
        if ([TCGBGamebase isSuccessWithError:error] == YES) {
            NSLog(@"Login is succeeded.");
        }
        else {
            if (error.code == TCGB_ERROR_SOCKET_ERROR || error.code == TCGB_ERROR_RESPONSE_TIMEOUT) {
                NSLog(@"Retry loginForLastLoggedInProviderWithCompletion: or Notify to user -\n\terror[%@]", [error description]);
            }
            else {
                NSLog(@"Try to login with loginWithType:viewController:completion:");
                [TCGBGamebase loginWithType:idpType viewController:topViewController completion:^(TCGBAuthToken *authToken, TCGBError *error) {
                    if ([TCGBGamebase isSuccessWithError:error] == YES) {
                        NSLog(@"Login is succeeded.");
                    }
                    else {
                        NSLog(@"Login is failed.");
                    }
                }];
            }
        }
    }];
}

Declared In

TCGBGamebase.h

+ loginWithCredential:viewController:completion:

Try to login with credential information received from External SDK or OAuth.

+ (void)loginWithCredential:(NSDictionary *)credentialInfo viewController:(UIViewController *)viewcontroller completion:(LoginCompletion)completion

Parameters

credentialInfo

NSDictionary value that contains provider_name (guest, faceboo, payco, iosgamecenter), access_token of IDP, access_token_secret of IDP that receive from IDP SDK.

viewcontroller

UIViewController object that present login view controller.

completion

callback that returned whether login is success or fail and return TCGBAuthToken.

Discussion

Usage Example

- (void)onButtonLogin {
    UIViewController* topViewController = nil;
    NSString* facebookAccessToken = @"feijla;feij;fdklvda;hfihsdfeuipivaipef/131fcusp";
    NSMutableDictionary* credentialInfo = [NSMutableDictionary dictionary];
    credentialInfo[@"provider_name"] = @"facebook";
    credentialInfo[@"access_token"] = facebookAccessToken;
    [TCGBGamebase loginWithCredential:credentialInfo viewController:topViewController completion:^(TCGBAuthToken *authToken, TCGBError *error) {
        if ([TCGBGamebase isSuccessWithError:error] == YES) {
            NSLog(@"Login is succeeded.");
        }
        else {
            if (error.code == TCGB_ERROR_SOCKET_ERROR || error.code == TCGB_ERROR_RESPONSE_TIMEOUT) {
                NSLog(@"Retry loginForLastLoggedInProviderWithCompletion: or Notify to user -\n\terror[%@]", [error description]);
            }
            else {
                NSLog(@"Try to login with loginWithType:viewController:completion:");
                [TCGBGamebase loginWithType:idpType viewController:topViewController completion:^(TCGBAuthToken *authToken, TCGBError *error) {
                    if ([TCGBGamebase isSuccessWithError:error] == YES) {
                        NSLog(@"Login is succeeded.");
                    }
                    else {
                        NSLog(@"Login is failed.");
                    }
                }];
            }
        }
    }];

Declared In

TCGBGamebase.h

+ loginForLastLoggedInProviderWithCompletion:

Try to login for last logged in ID Provider. This method use local stored name of last logged in IDP.

+ (void)loginForLastLoggedInProviderWithCompletion:(LoginCompletion)completion

Parameters

completion

callback that return whether login success or fail and return TCGBAuthToken

Discussion

This method try to login with local stored TCGBAuthToken.

Usage Example

- (void)onButtonLogin {
    NSString* idpType = @"facebook";
    UIViewController* topViewController = nil;

    [TCGBGamebase loginForLastLoggedInProviderWithCompletion:^(TCGBAuthToken *authToken, TCGBError *error){
        if ([TCGBGamebase isSuccessWithError:error] == YES) {
            NSLog(@"Login is succeeded.");
        }
        else {
            if (error.code == TCGB_ERROR_SOCKET_ERROR || error.code == TCGB_ERROR_RESPONSE_TIMEOUT) {
                NSLog(@"Retry loginForLastLoggedInProviderWithCompletion: or Notify to user -\n\terror[%@]", [error description]);
            }
            else {
                NSLog(@"Try to login with loginWithType:viewController:completion:");
                [TCGBGamebase loginWithType:idpType viewController:topViewController completion:^(TCGBAuthToken *authToken, TCGBError *error) {
                    if ([TCGBGamebase isSuccessWithError:error] == YES) {
                        NSLog(@"Login is succeeded.");
                    }
                    else {
                        NSLog(@"Login is failed.");
                    }
                }];
            }
        }
    }];
}

Declared In

TCGBGamebase.h

Mapping API

+ addMappingWithType:viewController:completion:

If you have logged in with an IDP Type. You can map with the other ID Providers, excluding Logged in IDP type.

+ (void)addMappingWithType:(NSString *)type viewController:(UIViewController *)viewController completion:(LoginCompletion)completion

Parameters

type

String value of IDPType name (guest, facebook, payco, iosgamecenter).

viewController

UIViewController object that present login view controller.

completion

callback that return whether addMapping is success or fail and return TCGBAuthToken. If you received TCGB_ERROR_AUTH_ADD_MAPPING_ALREADY_MAPPED_TO_OTHER_MEMBER or TCGB_ERROR_AUTH_ADD_MAPPING_ALREADY_HAS_SAME_IDP error, A TCGBAuthToken received from completion is not for current userID, but for already mapped account.

Discussion

Mapping IDPs are just mapped to TCGB UserID. ID Provider type what mapped to UserID only can be removed from mapped UserID.

Warning: Warning: Logged in ID Provider type cannot be removed from UserID.

Warning: Warning: You can call addMapping after logged in.

Usage Example

- (void)onButtonAddMapping {
    NSString* idpType = @"facebook";

    [TCGBGamebase addMappingWithType:idpType viewController:nil completion:^(TCGBAuthToken *authToken, TCGBError *error) {
        if ([TCGBGamebase isSuccessWithError:error] == YES) {
            NSLog(@"addMapping is succeeded.");
        }
        else {
            NSLog(@"addMapping is failed with Error:[%@]", [error description]);
            if (error.code == TCGB_ERROR_AUTH_ADD_MAPPING_ALREADY_MAPPED_TO_OTHER_MEMBER || error.code == TCGB_ERROR_AUTH_ADD_MAPPING_ALREADY_HAS_SAME_IDP) {
                NSLog(@"This ID Provider type has mapped to the other UserID");
            }
            else {
                NSLog(@"addMapping is failed with error:[%@]", [error description]);
            }
        }
    }];
}

Declared In

TCGBGamebase.h

+ removeMappingWithType:completion:

Disconnect ID Provider from UserID.

+ (void)removeMappingWithType:(NSString *)type completion:(RemoveMappingCompletion)completion

Parameters

type

String value of IDPType name (guest, facebook, payco, iosgamecenter).

completion

callback that return whether removeMapping is success or fail.

Discussion

Warning: Warning: You cannot remove mapping last logged in ID Provider.

Usage Example

- (void)onButtonRemoveMapping {
    NSString* idpType = @"facebook";

    [TCGBGamebase removeMappingWithType:idpType completion:^(TCGBError *error) {
        NSLog(@"removeMappingWityType:%@ is %@", idpType, [TCGBGamebase isSuccessWithError:error] == YES ? @"success":@"fail");
    }];
}

Declared In

TCGBGamebase.h

Logout API

+ logoutWithCompletion:

This method make user logout from TCGB Game Platform.

+ (void)logoutWithCompletion:(LogoutCompletion)completion

Parameters

completion

callback that return whether logout is success or fail

Discussion

This method try to logout from ID Provider SDK.

Usage Example

- (void)onButtonWithdrawal {
    [TCGBGamebase logoutWithCompletion:^(TCGBError *error) {
        NSLog(@"You have withdrew from TCGBGamebase : %@, [error debugDescription]);
    }];
}

Declared In

TCGBGamebase.h

Withdrawal API

+ withdrawWithCompletion:

This method make user withdraw from TCGB Game Platform, but IDPs need to be unlink in each IDP user preference page.

+ (void)withdrawWithCompletion:(WithdrawCompletion)completion

Parameters

completion

callback that return whether withdrawal is success or fail

Discussion

This method cannot drop out of IDP.

Usage Example

 - (void)onButtonWithdrawal {
     [TCGBGamebase withdrawWithCompletion:^(TCGBError *error) {
        NSLog(@"You have withdrew from TCGBGamebase : %@, [error debugDescription]);
     }];
 }

Declared In

TCGBGamebase.h

Login Information

+ lastLoggedInProvider

Method that return which IDP have been logged in at last time.

+ (NSString *)lastLoggedInProvider

Return Value

An String that has name of IDPs.

Discussion

Usage Example

- (void)onButtonGettingLastLoggedinProvider {
    NSString* lastProvider = [TCGBGamebase lastLoggedInProvider];
    NSLog(@"lastLoggedInProvider returns %@", lastProvider];
}

Declared In

TCGBGamebase.h

+ authMappingList

Method that returns which IDPs have been mapped to current UserID.

+ (NSArray *)authMappingList

Return Value

An Array that has name of IDPs.

Discussion

Usage Example

- (void)onButtonGettingMappedAuthList {
    NSArray* authList = [TCGBGamebase authMappingList];
    NSLog(@"authMappingList returns %@", [authList description]);
}

Declared In

TCGBGamebase.h

ID Provider Information

+ authProviderUserIDWithIDPCode:

Method that return UserID of ID Provider such as ‘facebook’, ‘payco’, ‘iosgamecenter’ and etc.

+ (NSString *)authProviderUserIDWithIDPCode:(NSString *)IDPCode

Parameters

IDPCode

IDPCode string value that you want to get.

Return Value

A String value of user ID.

Discussion

Usage Example

- (void)onButtonGettingIDPUserName {
    NSString* userID = [TCGBGamebase authProviderUserIDWithIDPCode:@"facebook"];
    NSLog(@"authProvider UserID = %@", userID);
}

Declared In

TCGBGamebase.h

+ authProviderAccessTokenWithIDPCode:

Method that return AccessToken of ID Provider such as ‘facebook’, ‘payco’, ‘iosgamecenter’ and etc.

+ (NSString *)authProviderAccessTokenWithIDPCode:(NSString *)IDPCode

Parameters

IDPCode

IDPCode string value that you want to get.

Return Value

A String value of AccessToken.

Discussion

Usage Example

- (void)onButtonGettingIDPAccessToken {
    NSString* accessToken = [TCGBGamebase authProviderAccessTokenWithIDPCode:@"facebook"];
    NSLog(@"authProvider AccessToken = %@", accessToken);
}

Declared In

TCGBGamebase.h

+ authProviderProfileWithIDPCode:

Method that return Profile Information of ID Provider such as ‘facebook’, ‘payco’, ‘iosgamecenter’ and etc.

+ (TCGBAuthProviderProfile *)authProviderProfileWithIDPCode:(NSString *)IDPCode

Parameters

IDPCode

IDPCode string value that you want to get.

Return Value

A String value of profile.

Discussion

Usage Example

  • (void)onButtonGettingIDPProfile { NSString* profile = [TCGBGamebase authProviderProfileWithIDPCode:@“facebook”]; NSLog(@“authProvider profile = %@”, profile); }

Declared In

TCGBGamebase.h

+ application:willFinishLaunchingWithOptions:

If you implement custom AuthAdapoter with TCGBAuthAdapterDelegate to support custom IDPs and you need to be called ‘application:willFinishLaunchingWithOptions:’ in your adapter class. This method must be called in ‘UIApplicationDelegate application:willFinishLaunchingWithOptions:’ method.

+ (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Parameters

application

Your singleton app object from UIApplication.

launchOptions

A dictionary indicating the reason the app will launch.

Discussion

This method is optional.

Usage Example

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return [TCGBGamebase application:application willFinishLaunchingWithOptions:launchOptions];
}

Declared In

TCGBGamebase.h

+ application:didFinishLaunchingWithOptions:

If you implement custom AuthAdapoter with TCGBAuthAdapterDelegate to support custom IDPs and you need to be called ‘application:didFinishLaunchingWithOptions:’ in your adapter class. This method must be called in ‘UIApplicationDelegate application:didFinishLaunchingWithOptions:’ method.

+ (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Parameters

application

Your singleton app object from UIApplication.

launchOptions

A dictionary indicating the reason the app was launched.

Discussion

This method is optional.

Usage Example

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return [TCGBGamebase application:application didFinishLaunchingWithOptions:launchOptions];
 }

Declared In

TCGBGamebase.h

+ application:didReceiveRemoteNotification:fetchCompletionHandler:

Responding to Notifications and Events

+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void ( ^ ) ( UIBackgroundFetchResult result ))completionHandler

Declared In

TCGBGamebase.h

+ application:openURL:options:

If you implement custom AuthAdapoter with TCGBAuthAdapterDelegate to support custom IDPs and you need to be called ‘application:openURL:options:’ in your adapter class. This method must be called in ‘UIApplicationDelegate application:openURL:options:’ method.

+ (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options

Parameters

app

Your singleton app object from UIApplication.

url

The URL resource to open.

options

A dictionary of URL handling options.

Return Value

YES if the delegate sucessfully handled the request or NO if the attempt to open the URL resource failed.

Availability

iOS 9.0 <=

Discussion

This method is optional.

Usage Example

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    return [TCGBGamebase application:app openURL:url options:options];
}

Declared In

TCGBGamebase.h

+ application:openURL:sourceApplication:annotation:

If you implement custom AuthAdapoter with TCGBAuthAdapterDelegate to support custom IDPs and you need to be called ‘application:openURL:sourceApplication:annotation:’ in your adapter class. This method must be called in ‘UIApplicationDelegate application:openURL:sourceApplication:annotation:’ method.

+ (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

Parameters

application

Your singleton app object from UIApplication.

url

The URL resource to open.

sourceApplication

The bundle ID of the app that is requesting your app to open the URL.

annotation

A Property list supplied by the source app to communicate information to the receiving app.

Return Value

YES if the delegate sucessfully handled the request or NO if the attempt to open the URL resource failed.

Availability

iOS 4.2 ~ 8.x

Discussion

This method is optional.

Usage Example

+ (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [TCGBGamebase application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

Declared In

TCGBGamebase.h

+ application:handleOpenURL:

If you implement custom AuthAdapoter with TCGBAuthAdapterDelegate to support custom IDPs and you need to be called ‘application:handleOpenURL:’ in your adapter class. This method must be called in ‘UIApplicationDelegate application:handleOpenURL:’ method.

+ (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

Parameters

application

Your singleton app object from UIApplication.

url

The URL resource to open.

Return Value

YES if the delegate sucessfully handled the request or NO if the attempt to open the URL resource failed.

Availability

iOS 4.2 ~ 8.x

Discussion

This method is optional.

Usage Example

+ (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [TCGBGamebase application:application handleOpenURL:url];
}

Declared In

TCGBGamebase.h