메타 데이터의 끝으로 건너뛰기
메타 데이터의 시작으로 이동

You are viewing an old version of this content. View the current version.

현재와 비교 View Version History

« 이전 버전 9 다음 »


Initialization and Status Change Event Processing


SDK Initialization

This process sets and initializes the app information used by the SDK.

It must be called before any other API when the game starts.

using KakaoGame.API;

KGTApplication.InitSDK();

Start

When a game is started, it must call the Start function to notify the Kakao Game SDK that it has been started.

UI functions such as platform announcements, update news, and term agreements are performed when the Start function of the Kakao Game SDK is called.

If there exists a prior user login record, the automatic login function is also performed, and the result is sent through the callback function inputted in the game when the method is called.

Therefore, the game can use the results to decide whether to authenticate the user first or whether to resume a previous game.

using KakaoGame.API;

KGTApplication.Start((result) =>
{
    if (result.IsSuccess)
    {
        // Start successful
        if (KGTPlayer.IsLoggedIn) 
        {
            // Auto login successful
            // The current Player's ID issued by the platform
            string playerId = KGTPlayer.CurrentPlayer.PlayerId;
            // Platform access token
            string accessToken = KGTPlayer.AccessToken;
            // Retrieve the current IDP authentication information
            var idpProfile = KGTPlayer.CurrentPlayer.IdpProfile;
            // [TODO] Log in to the game server and proceed to the game screen
        } 
        else 
        {
            // No auto login information, call the login API
        }
    }
    else 
    {
        if (result.code == KGTResultCode.NetworkFailure ||
            result.code == KGTResultCode.ServerTimeout ||
            result.code == KGTResultCode.ServerConnectionFailed) 
        {
            // [TODO] In case of a network error, notify the user that the start failed due to network issues and retry
        } 
        else 
        {
            // [TODO] Notify the user that an error occurred. It would be helpful to include the error code in the message for tracking the cause.
        }
    }
});

Pause

If the game is moved to the background, the game must call the Pause API to notify the Kakao Game SDK that it has become inactive.

When the Pause API is called, the Kakao Game SDK disconnects the connected session and stops periodically sending heartbeats to prevent battery consumption.

using KakaoGame.API;

// Implement in the background transition function of appDelegate
// [Note] Implement in OnApplicationPause.
// [Note] Do not implement in OnApplicationFocus.
void OnApplicationPause(bool paused) {
    // Method to be executed when the game moves to the background
    // The Pause API always returns success.
    // Therefore, you do not need to check the result separately in the game.
    if (paused)
    {
        KGTApplication.Pause((result) => {});
    }
}

Resume

If the game is moved back to the foreground from the background, it must call the Resume API to notify the Kakao Game SDK that it has become active.

The Kakao Game SDK checks whether the authentication has expired when the Resume method is called and restores the session depending on the check. The result is then sent through the callback function inputted in the game when the method is called.

The game can use the results to decide whether to authenticate the user again or whether to resume a previous game.

using KakaoGame.API;

// Implement in the background transition function of appDelegate
// [Note] Implement in OnApplicationPause.
// [Note] Do not implement in OnApplicationFocus.
void OnApplicationPause(bool paused) {
    if (!paused) // When moved to the foreground
    {
        // Method to be executed when the game moves to the foreground
        KGTApplication.Resume((result) => 
        {
            if (result.IsSuccess) 
            {
                // [TODO] If resume is successful, resume the game screen.
            } 
            else 
            {
                // [TODO] If resume fails, navigate to the login screen if it’s an authentication failure; otherwise, show an error popup and check if the user wants to retry.
                if (result.code == KGTResultCode.AuthFailure ||
                    result.code == KGTResultCode.IdpAuthFailure) 
                {
                    // [TODO] In case of authentication failure, move to the start screen and perform the new login flow again.
                } 
                else 
                {
                    // [TODO] If other errors occur, provide an error notification and retry the resume.
                }
            }
        });
    }
}

Setting Up Auto Login in a Windows Environment

This feature is supported in the Windows environment.

If you do not use the default login UI provided by the SDK and instead implement your own login UI, the SDK offers a feature to set up auto login.

  • If you do not configure auto login, the SDK will not create a file for automatic login by default.

  • The file for auto login is created and stored in an encrypted format in the folder ".kakaogames" under the name ".access". This is because multiple users can exist on a single PC."

  • When a game is uninstalled and then reinstalled, if the auto login file remains, the SDK checks whether an encrypted ".access" file exists in the location of the Windows SDK file (KakaoGame.dll). If the file is valid, the SDK loads the file containing the auto login information and performs the auto login.

  • If the auto login files are corrupted, the SDK will delete them.

  • If the auto login file exists and the user logs out or withdraws, the auto login file will be deleted.

using KakaoGame.API;

// Set whether to use auto-login; if not set, it defaults to not using auto-login.
// When auto-login is enabled and login is successful, auto-login information is generated.
// If auto-login information exists, the next time KGTApplication starts, auto-login will proceed automatically. To remove the auto-login information, you must log out.
bool useAutoLogin = true;
KGTApplication.UseAutoLogin = useAutoLogin;

Login


  • The login UI can be customized and applied by the developer.

  • Considerations When Implementing Login UI Directly

    • Login APIs are provided for each IDP (Identity Provider).

    • When implementing the login screen, the developer should place login buttons for each IDP and implement the logic so that clicking each button calls the corresponding IDP's login API.

    • If a global build is provided, the visibility of IDP buttons should be handled according to the country. For example, in South Korea, Kakao Login should be provided, while in other countries, Facebook Login may be provided.

    • To differentiate by country, an API in the KGTSystem class is provided to retrieve the countryCode.

  •  After a successful login, if the settings screen is displayed, it should be implemented so that the PlayerID is shown as the member number.

Logging In Without Using the Default Login UI

This is an example of logging in without using the default login UI.

If the login IDP varies by country, use the API to retrieve the country and handle branching accordingly.

  • Guest Verification

In the case of guest login, an alert popup must be implemented by the developer. This is a mandatory checkpoint during Kakao Games inspection.

Before proceeding with guest verification, an alert popup should be displayed with the message: "If you delete the game or change devices, game data may be lost when logging in as a guest." This allows the user to choose whether to continue with guest verification or cancel.

Example)

When guest login is used, if the app is deleted or the device information is changed, the game cannot continue with the previous playerId.

If using the default login, the SDK provides this alert automatically.

using KakaoGame.API;

KGTIdpCode idpCode = KGTIdpCode.Kakao;

KGTPlayer.Login(idpCode, (result) =>
{
    if (result.IsSuccess) 
    {
        // Handle successful login.
        // The current Player's ID issued by the platform
        string playerId = KGTPlayer.CurrentPlayer.PlayerId;
        // Platform access token
        string accessToken = KGTPlayer.AccessToken;
        // Retrieve the current IDP authentication information
        var idpProfile = KGTPlayer.CurrentPlayer.IdpProfile;
        // [TODO] Log in to the game server and proceed to the game screen
    } 
    else 
    {
        // Handle login failure.
        if (result.code == KGTResultCode.NetworkFailure ||
            result.code == KGTResultCode.ServerTimeout ||
            result.code == KGTResultCode.ServerConnectionFailed) 
        {
            // [TODO] If a network error occurs, prompt the user to retry logging in.
        } 
        else if (result.code == KGTResultCode.Forbidden) 
        {
            // [TODO] During the CBT period, authentication may not be possible for users who are not allowed. Display a notification to the user, and after clicking confirm, implement the app to exit.
        } 
        else if (result.code == KGTResultCode.UserCanceled) 
        {
            // [TODO] Since the user canceled during the login process, the login screen should be maintained.
        } 
        else 
        {
            // [TODO] If other errors occur, provide an error notification and prompt the user to retry logging in.
            // It is necessary to check the error code and logs to determine the cause.
        }
    }
});

Logging In Through the Launcher

This API is used when performing SDK login through a launcher (supported in Windows environments).

Login is performed using the bridgeToken received from the launcher.

After logging in, any additional information received through the launcher can be checked in the player information.

using KakaoGame.API;

// The bridgeToken received through the launcher
string bridgeToken = "";

KGTPlayer.LoginWithBridgeToken(bridgeToken, (result) =>
{
    if (result.IsSuccess) 
    {
        // Handle successful login.
        // The current Player's ID issued by the platform
        string playerId = KGTPlayer.CurrentPlayer.PlayerId;
        // Platform access token
        string accessToken = KGTPlayer.AccessToken;
        // Retrieve the current IDP authentication information
        var idpProfile = KGTPlayer.CurrentPlayer.IdpProfile;
        // [TODO] Log in to the game server and proceed to the game screen
    } 
    else 
    {
        // Handle login failure.
        if (result.code == KGTResultCode.NetworkFailure ||
            result.code == KGTResultCode.ServerTimeout ||
            result.code == KGTResultCode.ServerConnectionFailed) 
        {
            // [TODO] If a network error occurs, prompt the user to retry logging in.
        } 
        else if (result.code == KGTResultCode.Forbidden) 
        {
            // [TODO] During the CBT period, authentication may not be possible for users who are not allowed. Display a notification to the user, and after clicking confirm, implement the app to exit.
        } 
        else if (result.code == KGTResultCode.UserCanceled) 
        {
            // [TODO] Since the user canceled during the login process, the login screen should be maintained.
        } 
        else 
        {
            // [TODO] If other errors occur, provide an error notification and prompt the user to retry logging in.
            // It is necessary to check the error code and logs to determine the cause.
        }
    }
});

Logout


  • The logout UI must be implemented directly by the developer.

    • Logout APIs are provided for each logout UI.

Logging Out Without Using the Default Logout UI

This is an example of logging out without using the default logout UI.

using KakaoGame.API;

KGTPlayer.Logout(false, (result) =>
{
    if (result.IsSuccess) 
    {
        // Logout successful
        // [TODO] Return to the start screen
    } 
    else 
    {
        // Logout failed
    }
});

Unregistration


  • If the developer wishes to implement the unregistration UI directly (or does not want to use the provided unregistration UI), an unregistration API is available.

Unregistering Without Using the Default Unregistration UI

This is an example of unregistering without using the default unregistration UI.

using KakaoGame.API;

KGTPlayer.Unregister(false, (result) =>
{
    if (result.IsSuccess) 
    {
        // Unregistration successful
        // [TODO] Return to the start screen
    } 
    else 
    {
        // Unregistration failed
    }
});

Account Linking


  • If the developer wishes to implement the account linking UI directly (or does not want to use the default account linking UI), an account linking API is provided for each IDP.

    • The developer should place account linking buttons for each IDP on the account linking screen, and implement the logic so that clicking each button calls the corresponding IDP's account linking API.

Linking Accounts Without Using the Default Account Linking UI

This is an example of linking accounts without using the default account linking UI.
If account linking is successful, the player ID will remain the same.

using KakaoGame.API;

KGTIdpCode idpCode = KGTIdpCode.Kakao;

KGTPlayer.Connect(idpCode, (result) =>
{
    if (result.IsSuccess) 
    {
        // Account connection successful
    } 
    else if (result.code == KGTResultCode.NotAuthorized) 
    {
        // When the current session is not authenticated
    }
    else if (result.code == KGTResultCode.InvalidState) 
    {
        // When the account is already connected
    }
    else if (result.code == KGTResultCode.AlreadyUsedIDPAccount) 
    {
        // When attempting to connect with an IDP account that is already in use
    }
    else 
    {
        // Other errors
    }
});

Profile


Retrieve My Information

This is an example of retrieving my information.

using KakaoGame.API;

KGTPlayer player = KGTPlayer.CurrentPlayer;

Retrieve My IDP Information

This is an example of retrieving my IDP profile information.
You can retrieve the information provided by each IDP profile.

using KakaoGame.API;

KGTIdpProfile idpProfile = KGTPlayer.CurrentPlayer.IdpProfile;

System Information


Retrieve Language Code

Retrieves the language setting information of the device, returning a language code according to the ISO 639-1 standard.

using KakaoGame.API;

string languageCode = KGTSystem.LanguageCode;

Retrieve Country Code

The SDK collects the country code based on the initial GeoIP. The country code follows the ISO 3166-1 alpha-2 standard, and if no country information is available, "zz" is returned.
The country code initially determined when the app is first run is maintained, but if the logged-in user's country code information differs, the user's country code information is followed.

using KakaoGame.API;

string countryCode = KGTSystem.CountryCode;

Retrieve IP-based Country Code

Returns the country code based on the IP of the network to which the device is currently connected.

using KakaoGame.API;

string geoCountryCode = KGTSystem.GeoCountryCode;

Retrieve Device ID

Returns a value that uniquely identifies the device. This value changes if the device is reset.

using KakaoGame.API;

string deviceId = KGTSystem.DeviceId;

Retrieve Device Model

Returns the model information of the current device.

using KakaoGame.API;

string deviceModel = KGTSystem.DeviceModel;

Retrieve OS Name

Returns the name of the current device's OS (android/ios).

using KakaoGame.API;

string osName = KGTSystem.OsName;

Retrieve Network Connection Status

Returns whether the current device is connected to an external network.

using KakaoGame.API;

bool isNetworkConnected = KGTSystem.IsNetworkConnected;

Retrieve Connected Network Type

Retrieves the type of network to which the current device is connected (wifi/cellular/unknown).

using KakaoGame.API;

string networkType = KGTSystem.NetworkType;

Kakao Integration Feature


Setting Up KakaoTalk Game Message Reception

This is an example of how to set up the reception of KakaoTalk game messages for yourself.

using KakaoGame.API;

KGTKakaoTalk.ShowSetting((result) => 
{
    if (result.IsSuccess) 
    {
        // Successfully set the KakaoTalk game message reception settings
    }
    else if (result.code == KGTResultCode.NotKakaoTalkUser)
    {
        // The logged-in user is not a 'KakaoTalk' user. This occurs when the user is only registered with KakaoStory and not KakaoTalk.
    }
    else 
    {
        // Failed to set the KakaoTalk game message reception settings
    }
});

Retrieve KakaoTalk Profile

This is an example of how to retrieve your own KakaoTalk profile.

using KakaoGame.API;

KGTKakaoTalk.TalkProfile((result) => 
{
    if (result.IsSuccess) 
    {
        // Successfully retrieved KakaoTalk profile
        KGTKakaoTalkProfile talkProfile = result.Content;
    }
    else if (result.code == KGTResultCode.NotKakaoTalkUser)
    {
        // The logged-in user is not a 'KakaoTalk' user. This occurs when the user is only registered with KakaoStory and not KakaoTalk.
    }
    else 
    {
        // Failed to retrieve KakaoTalk profile
    }
});

Retrieve KakaoTalk Game Friend List

This is an example of how to retrieve your KakaoTalk game friend list.

using KakaoGame.API;

KGTKakaoTalk.Friends((result) => 
{
    if (result.IsSuccess) 
    {
        var players = result.Content;
        // Successfully retrieved KakaoTalk game friends list.
        foreach(var player in players) {
            var kakaoProfile = (KGTKakaoProfile)player.IdpProfile; // Used when sending game messages
        }
    }
    else if (result.code == KGTResultCode.NotKakaoTalkUser)
    {
        // The logged-in user is not a 'KakaoTalk' user. This occurs when the user is only registered with KakaoStory and not KakaoTalk.
    }
    else 
    {
        // Failed to retrieve KakaoTalk game message reception settings
    }
});

Sending KakaoTalk Game Messages

This is an example of sending a KakaoTalk game message using a message template.
If you want to receive specific parameters when the recipient taps the message to enter the game, you can set the exec parmin the message template.
When the recipient receives the message on KakaoTalk and taps the connection link, the app will launch and pass the exec param.
You can use this value to start a specific stage or provide predefined items. Please note that the exec param can only be used with game messages.

using KakaoGame.API;

// Through the Friends API
KGTKakaoFriendProfile kakaoProfile; // Kakao profile (KGTKakaoFriendProfile object)

// [TODO] Set the template Id
string templateId;
  
// [TODO] Set the arguments for the message template
Dictionary<string, object> argumentDic = new Dictionary<string, object>();

KGTKakaoTalk.SendGameMessage(kakaoProfile, templateId, argumentDic, (result) => 
{
    if (result.IsSuccess) 
    {
        // Successfully sent a KakaoTalk chat message.
    }
    else if (result.code == KGTResultCode.MessageSettingDisabled) 
    {
        // The recipient has set message reception to be disabled.
    }
    else if (result.code == KGTResultCode.ExceedDailyUsage) 
    {
        // Occurs when the daily quota for sending messages to a specific app (regardless of the recipient) is exceeded.
    }
    else if (result.code == KGTResultCode.ExceedMonthlyUsage) 
    {
        // Occurs when the monthly quota for sending messages to a specific person for a specific app is exceeded.
    }
    else if (result.code == KGTResultCode.NotKakaoTalkUser)
    {
        // The logged-in user is not a 'KakaoTalk' user. This occurs when the user is only registered with KakaoStory and not KakaoTalk.
    }
    else 
    {
        // Failed to send KakaoTalk chat message.
    }
});

Sending KakaoTalk Friend Invitation Messages

This example demonstrates how to send an invitation message using the KakaoTalk Friend Picker.
Depending on the isSingle option, you can send invitation messages to multiple friends.
If you send invitation messages to multiple friends, a success response is returned even if only one friend successfully receives the message.
The isPopup option allows you to display the Friend Picker in a popup form. This feature is supported through the KakaoSDK but is not supported in the Windows SDK.

using KakaoGame.API;

// [TODO] Set whether to display as a popup window
bool isSingle;

// [TODO] Set whether to display as a popup window
bool isPopup;
  
// [TODO] Set the template Id
string templateId;
  
// [TODO] Set the arguments for the message template
Dictionary<string, object> argumentDic = new Dictionary<string, object>();

KGTKakaoTalk.SendInviteMessage(isSingle, isPopup, templateId, argumentDic, (result) =>
{
    if (result.IsSuccess) 
    {
        // Request successful
    }
    else
    {
        // Request failed
        if (result.code == KGTResultCode.MessageSettingDisabled)
        {
            // The recipient has set message reception to be disabled.
        }
        else if (result.code == KGTResultCode.ExceedDailyUsage)
        {
            // Occurs when the daily quota for sending messages to a specific app (regardless of the recipient) is exceeded.
        }
        else if (result.code == KGTResultCode.ExceedMonthlyUsage)
        {
            // Occurs when the monthly quota for sending messages to a specific person for a specific app is exceeded.
        }
        else if (result.code == KGTResultCode.NotKakaoTalkUser)
        {
            // The logged-in user is not a 'KakaoTalk' user.
        }
        else
        {
            // Other errors
        }
    }
});

Adding a KakaoTalk Channel

This is an example of how to add a KakaoTalk channel.

using KakaoGame.API;

// [TODO] Set the channel Id
int channelId;

KGTKakaoTalk.AddChannel(channelId, (result) => 
{
    if (result.IsSuccess) 
    {
        // Successfully added friend
    }
    else if (result.code == KGTResultCode.NotKakaoTalkUser)
    {
        // The logged-in user is not a 'KakaoTalk' user. This occurs when the user is only registered with KakaoStory and not KakaoTalk.
    }
    else
    {
        // Failed to add friend
    }
});
  • 레이블 없음

0 댓글

로그인 상태가 아닙니다. 변경하는 경우 익명으로 표기됩니다. 이미 계정이 있다면 로그인을 원하실 수 있습니다.