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

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

현재와 비교 View Version History

« 이전 버전 7 현재 »


Initialization and Status Change Event Processing


App Event Method Initialization (iOS Only)

This process initializes the SDK to handle AppDelegate methods.

It must be called within the AppDelegate class.

import KakaoGameTube

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

	var window: UIWindow?
	
	override init() {
		KGTApplication.setSwizzleAppDelegate(delegate: AppDelegate.description())
	}

}

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.

import KakaoGameTube

/**
 * When using a single app
 */
let config = KGTConfig(appId: "909428",
                       appSecret: "c3c38bbfa3828b342d946e9770c974d0",
                       appVersion: "1.0.0",
                       market: "appStore",
                       ageRating: "14",
                       serverType: .QA,
                       logLevel: .Verbose)

/**
 * When using an app group
 */
let apps: [String : String] = [ "909428" : "c3c38bbfa3828b342d946e9770c974d0",
                                "921478" : "5891c32124ca35821890a0bc1cec77a5"]
let config = KGTConfig(appGroupId: "tubeAppGroup",
                       apps: apps,
                       appVersion: "1.0.0",
                       market: "appStore",
                       ageRating: "14",
                       serverType: .QA,
                       logLevel: .Verbose)

KGTApplication.initSDK(config)

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.

import KakaoGameTube

KGTApplication.start { error in
	if error.isSuccess {
		// If the start is successful
				
		// Check if auto-login is enabled
		let isLoggedIn = KGTPlayer.isLoggedIn
				
		if isLoggedIn {
			// The current Player's ID issued by the platform
			let playerId = KGTPlayer.currentPlayer?.playerId
					
			// Platform access token
			let accessToken = KGTPlayer.accessToken
					
			// Retrieve the current IDP authentication information
			let idpProfile = KGTPlayer.currentPlayer?.idpProfile
					
			// [TODO] Move to the game screen.
		} else {
			// [TODO] If auto-login is not enabled, move to the login screen.
		}
				
	} else {
		//If the start fails - since initialization failed, retry the start or close the app.
				
		if error.code == KGTErrorCode.networkFailure ||
			error.code == KGTErrorCode.serverTimeout ||
			error.code == KGTErrorCode.serverConnectionFalied {
			// [TODO] If a network error occurs, notify the user that the start failed due to a network issue and retry.
		} else {
			// [TODO] If other errors occur, provide an error notification and request a retry of the start process. - If the issue persists, check the error code and logs to determine 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.

import KakaoGameTube
 
KGTApplication.pause()

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.

import KakaoGameTube
 
KGTApplication.resume { error in
	if error.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 error.code == KGTErrorCode.authFailure ||
			error.code == KGTErrorCode.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. - If the issue persists, close the app.
		}
	}
})

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.

import KakaoGameTube

// Set the IdpCode for login
let idpCode = KGTIdpCode.Kakao

// Login with a specific IDP
KGTPlayer.login(with: idpCode) { error in
	if error.isSuccess {
		// IDP login and platform login successful

        // The current Player's ID issued by the platform
		let playerId = KGTPlayer.currentPlayer?.playerId
					
		// Platform access token
		let accessToken = KGTPlayer.accessToken
					
		// Retrieve the current IDP authentication information
		let idpProfile = KGTPlayer.currentPlayer?.idpProfile

		// [TODO] Since login was successful, proceed to the game screen.
	} else {
		// IDP login or platform login failed
		// [TODO] If login fails, inform the user and prompt them to retry.

        if error.code == KGTErrorCode.networkFailure ||
			error.code == KGTErrorCode.serverTimeout ||
			error.code == KGTErrorCode.serverConnectionFailed {
			// [TODO] If other errors occur, provide an error notification and prompt the user to retry logging in.
		} else if error.code == KGTErrorCode.blockedByPolicy {
			// [TODO] Login attempt from a blocked country code or IP range. Handle this accordingly.
        } else if error.code == KGTErrorCode.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.

import KakaoGameTube

// Logout request
KGTPlayer.logout(showUI: false) { error in
    if error.isSuccess {
        // Logout successful

        // [TODO] Return to the start screen
    } else {
        // Logout failed
    }
})

Unregistration


  • 탈퇴 UI를 개발사에서 직접 구현하고 싶을 경우(탈퇴 UI를 사용하고 싶지 않은 경우)를 위해서, 탈퇴 API가 제공됩니다.

Unregistering Without Using the Default Unregistration UI

기본 탈퇴 UI를 사용하지 않는 탈퇴하는 예제입니다.

import KakaoGameTube

// Unregister request
KGTPlayer.unregister(showUI: false) { error in 
    if error.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.

import KakaoGameTube

// Set the IdpCode you want to log in with
let idpCode = KGTIdpCode.Kakao

// Connect to a specific IDP account
KGTPlayer.connect(idpCode: idpCode) { error in 
    if error.isSuccess {
        // IDP connection successful
        // Player ID does not change.
    } else {
        // IDP connection failed

        if error.code == KGTErrorCode.invalidParameter {
            // Invalid parameter was passed
        } else if error.code == KGTErrorCode.notAuthorized {
            // The user is not currently logged in
        } else if error.code == KGTErrorCode.invalidState {
            // The current authenticated IDP is not eligible for account connection
        } else if error.code == KGTErrorCode.alreadyUsedIdpAccount {
            // The account is already connected
        } else {
            // Other errors occurred
        }
    }
})

Profile


Retrieve My Information

This is an example of retrieving my information.

import KakaoGameTube

let localPlayer = 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.

import KakaoGameTube

let 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.

import KakaoGameTube

let 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.

import KakaoGameTube

let 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.

import KakaoGameTube

let countryCode = KGTSystem.geoCountryCode

Retrieve Device ID

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

import KakaoGameTube

let deviceId = KGTSystem.deviceId

Retrieve Device Model

Returns the model information of the current device.

import KakaoGameTube

let deviceModel = KGTSystem.deviceModel

Retrieve OS Name

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

import KakaoGameTube

let osName = KGTSystem.osName

Retrieve Network Connection Status

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

import KakaoGameTube

let isNetworkConnected = KGTSystem.isNetworkConnected

Retrieve Connected Network Type

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

import KakaoGameTube

let 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.

import KakaoGameTube
import KakaoGameTubeKakao

// Display the view to set the KakaoTalk game message reception settings
KGTKakaoTalk.showSetting { error, isAllowedMe in
    if error.isSuccess {
        // Successfully set the KakaoTalk game message reception settings
        let isAllowedMe = isAllowedMe // Whether message reception is allowed as per the settings
    } else if error.code == KGTErrorCode.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.

import KakaoGame
import KakaoGameKakao
// Retrieve KakaoTalk profile
KGTKakaoTalk.talkProfile { error, profile in
	if error.isSuccess {
		// Successfully retrieved KakaoTalk profile
		let talkProfile = profile // The KakaoTalk profile information of the logged-in user
    } else if error.code == KGTErrorCode.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.

import KakaoGameTube
import KakaoGameTubeKakao

// Retrieve the list of game friends
KGTKakaoTalk.friends { error, players in
    if error.isSuccess {
        // Successfully retrieved KakaoTalk game friends list.
        for player in players {
            if let kakaoFriendProfile = player.idpProfile as? KGTKakaoFriendProfile {
                // You can now access kakaoFriendProfile properties here
            }
        }
    } else if error.code == KGTErrorCode.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 friends list
    }
})

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.

import KakaoGameTube
import KakaoGameTubeKakao

// Friend object retrieved via the friends API
let kakaoProfile: KGTKakaoFriendProfile = // Kakao profile (KGTKakaoFriendProfile object)

// [TODO] Set the template Id
let templateId = ""

// [TODO] Set the arguments for the message template
var argumentDic: [String: Any]? = [:]
argumentDic?["rog_link"] = "test=100&hello20111"
argumentDic?["bruce2"] = "test=100&hello=20111"

// Send KakaoTalk game message
KGTKakaoTalk.sendGameMessage(kakaoProfile: kakaoProfile, templateId: templateId, argumentDic: argumentDic) { error in
    if error.isSuccess {
        // Successfully sent KakaoTalk chat message
    } else {
        if error.code == KGTErrorCode.messageSettingDisabled {
            // The recipient has set message reception to be disabled.
        } else if error.code == KGTErrorCode.exceedDailyUsage {
            // Occurs when the daily quota for sending messages to a specific app (regardless of the recipient) is exceeded.
        } else if error.code == KGTErrorCode.exceedMonthlyUsage {
            // Occurs when the monthly quota for sending messages to a specific person for a specific app is exceeded.
        } 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.

import KakaoGameTube
import KakaoGameTubeKakao

// [TODO] Set whether to display as a popup window
let isSingle = true

// [TODO] Set whether to display as a popup window
let isPopup = true

// [TODO] Set the template Id
let templateId = ""

// [TODO] Set the arguments for the message template
var argumentDic: [String: Any]? = [:]
argumentDic?["rog_link"] = "test=100&hello20111"
argumentDic?["bruce2"] = "test=100&hello=20111"

KGTKakaoTalk.sendInviteMessage(isSingle: isSingle, isPopup: isPopup, templateId: templateId, argumentDic: argumentDic) { error, users in
    if error.isSuccess {
        // Successfully sent KakaoTalk invite message
        for user in users {
            // Check the list of users who received the invite message
        }
    } else {
        // Failed to send to all users (common cause needs to be returned)
        if error.code == KGTErrorCode.messageSettingDisabled {
            // The recipient has set message reception to be disabled.
        } else if error.code == KGTErrorCode.exceedDailyUsage {
            // Occurs when the daily quota for sending messages to a specific app (regardless of the recipient) is exceeded.
        } else if error.code == KGTErrorCode.exceedMonthlyUsage {
            // Occurs when the monthly quota for sending messages to a specific person for a specific app is exceeded.
        } else {
            // Failed to send KakaoTalk invite message
        }
    }
})

Adding a KakaoTalk Channel

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

import KakaoGameTube
import KakaoGameTubeKakao

// [TODO] Set the channel ID
let channelId = 0

KGTKakaoTalk.addChannel(channelId: channelId) { error in
    if error.isSuccess {
        // Successfully added the channel
    } else if error.code == KGTErrorCode.notKakaoTalkUser {
        // The logged-in user is not a KakaoTalk user. For example, they might only be a Kakao Story user and not a KakaoTalk user.
    } else {
        // Failed to add the channel
    }
})

Retrieve the list of friends to whom I sent an invite message

This is an example of viewing the list of friends to whom I have sent invitation messages.

If a user is not registered, their information is delivered as an empty object.

import KakaoGameTube
import KakaoGameTubeKakao

Retrieve the count of friends to whom I sent an invite message

This is an example of checking the number of friends to whom I have sent invitation messages.

import KakaoGameTube
import KakaoGameTubeKakao

  • 레이블 없음