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

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

현재와 비교 View Version History

« 이전 버전 2 다음 »


초기화 및 상태변화 이벤트 처리


앱 이벤트 메서드 초기화 (iOS Only)

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import KakaoGameTube

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

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

}

SDK 초기화

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import KakaoGameTube

/**
 * 단일 앱으로 사용하는 경우
 */
let config = KGTConfig(appId: "909428",
					   appSecret: "c3c38bbfa3828b342d946e9770c974d0",
					   appVersion: "1.0.0",
					   market: "appStore",
					   ageRating: "14",
					   serverType: .QA,
					   logLevel: .Verbose)

/**
 * 앱 그룹을 사용하는 경우
 */
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) 하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import KakaoGameTube

KGTApplication.start { error in
	if error.isSuccess {
		// 스타트가 성공 한 경우
				
		// 자동로그인 여부
		let isLoggedIn = KGTPlayer.isLoggedIn
				
		if isLoggedIn {
			// 플랫폼에서 발급한 현재 Player의 ID
			let playerId = KGTPlayer.currentPlayer?.playerId
					
			// 플랫폼 액세스 토큰
			let accessToken = KGTPlayer.accessToken
					
			// 현재 IDP 인증 정보를 가져옴
			let idpProfile = KGTPlayer.currentPlayer?.idpProfile
					
			// [TODO] 게임 화면으로 이동 합니다.
		} else {
			// [TODO] 자동로그인이 안 된 경우 로그인 화면으로 이동 합니다.
		}
				
	} else {
		// 스타트가 실패 한 경우 - 초기화가 실패한 경우 이므로 스타트를 재시도 하거나 앱을 종료 하여야 합니다.
				
		if error.code == KGTErrorCode.networkFailure ||
			error.code == KGTErrorCode.serverTimeout ||
			error.code == KGTErrorCode.serverConnectionFalied {
			// [TODO] 네트워크 에러가 발생한 경우에는 유저에게 네트워크 이슈로 스타트에 실패했음을 알리고 재시도
		} else {
			// [TODO] 나머지 에러가 발생한 경우에는 에러 안내 후 스타트 재시도 요청 하여야 합니다. - 문제가 반복해서 발생하는 경우 에러코드 및 로그 확인 후 원인 파악이 필요합니다.
		}
	}
}

Pause 하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import KakaoGameTube
 
KGTApplication.pause()

Resume 하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import KakaoGameTube
 
KGTApplication.resume { error in
	if error.isSuccess {
		// [TODO] resume이 성공 한 경우 게임 화면을 재개합니다.
	} else {
		// [TODO] resume이 실패 한 경우 인증 실패 면 로그인 화면으로, 그외의 경우는 에러 팝업을 띄우고 재시도 여부를 확인합니다.
		if error.code == KGTErrorCode.authFailure ||
			error.code == KGTErrorCode.idpAuthFailure {
			// [TODO] 인증 실패의 경우 시작 화면으로 이동해서 다시 신규 로그인 flow를 수행합니다.
		} else {
			// [TODO] 나머지 에러가 발생한 경우 경우 에러 안내 후 resume 을 재시도 합니다. - 반복해서 문제가 발생하는 경우 앱을 종료하도록 합니다.
		}
	}
})

로그인


매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Login SDK Example'.

기본 로그인 UI를 사용하지 않는 로그인하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Login SDK Example'.

import KakaoGameTube

// 로그인 하고자 하는 IdpCode 셋팅
let idpCode = KGTIdpCode.Kakao

// 특정 idp로 로그인 하기
KGTPlayer.login(with: idpCode) { error in
	if error.isSuccess {
		// IDP 로그인과 플랫폼 로그인 성공

        // 플랫폼에서 발급한 현재 Player의 ID
		let playerId = KGTPlayer.currentPlayer?.playerId
					
		// 플랫폼 액세스 토큰
		let accessToken = KGTPlayer.accessToken
					
		// 현재 IDP 인증 정보를 가져옴
		let idpProfile = KGTPlayer.currentPlayer?.idpProfile

		// [TODO] 로그인이 성공하였으므로 게임 화면으로 이동합니다.
	} else {
		// IDP 로그인 혹은 플랫폼 로그인 실패
		// [TODO] 로그인 실패 시 사용자 안내 후 재 시도 하도록 하여야 합니다.

        if error.code == KGTErrorCode.networkFailure ||
			error.code == KGTErrorCode.serverTimeout ||
			error.code == KGTErrorCode.serverConnectionFalied {
			// [TODO] 네트워크 에러가 발생한 경우에는 로그인 재시도 요청 하여야 합니다.
		} else if error.code == KGTErrorCode.blockedByPolicy {
			// [TODO] 차단당한 국가 코드 또는 IP 대역에서 로그인을 시도하였습니다. 이에 대한 처리가 필요합니다.
        } else if error.code == KGTErrorCode.userCanceled {    
			// [TODO] 사용자가 로그인 진행 중 취소한 상황이므로 로그인 화면을 유지 하여야 합니다.
		} else {
			// [TODO] 나머지 에러가 발생한 경우에는 에러 안내 후 로그인 재시도 요청 하여야 합니다. - 에러코드 및 로그 확인 후 원인 파악이 필요합니다.
		}
	}
})

로그아웃


매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Logout SDK Example'.

기본 로그아웃 UI를 사용하지 않는 로그아웃하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Logout SDK Example'.

import KakaoGameTube

// 로그아웃 요청
KGTPlayer.logout(showUI: false) { error in
	if error.isSuccess {
		// 로그아웃 성공

		// [TODO] 시작 화면으로 돌아가기
	} else {
		// 로그아웃 실패
	}
})

탈퇴


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

기본 탈퇴 UI를 사용하지 않는 탈퇴하기

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

import KakaoGameTube

// 탈퇴 요청
KGTPlayer.unregister(showUI: false) { error in 
	if error.isSuccess {
		// 탈퇴 성공

		// [TODO] 시작 화면으로 돌아가기
	} else {
		// 탈퇴 실패 
	}
})

계정 연결


매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Account Linking SDK Example'.

기본 계정 연결 UI를 사용하지 않는 계정 연결하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Account Linking SDK Example'.

import KakaoGameTube

// 로그인 하고자 하는 IdpCode 셋팅
let idpCode = KGTIdpCode.Kakao

// 특정 idp로 계정 연결 하기
KGTPlayer.connect(idpCode: idpCode) { error in 
	if error.isSuccess {
		// IDP 연결 성공
		// Player ID 는 변경되지 않습니다.
	} else {
		// IDP 연결 실패

		if error.code == KGTErrorCode.invalidParameter {
			// 잘못된 인자가 전달 된 경우
		} else if error.code == KGTErrorCode.notAuthorized {
			// 현재 로그인이 안되어 있는 경우
		} else if error.code == KGTErrorCode.invalidState {
			// 현재 인증 된 IDP 가 계정 연결 가능한 idp가 아닌 경우
		} else if error.code == KGTErrorCode.alreadyUsedIdpAccount {
			// 이미 연결되어 있는 계정이 있는 경우
		} else {
			// 기타 에러 발생
		}
	}
})

프로필


내 정보 조회하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Profile SDK Example'.

import KakaoGameTube

let localPlayer = KGTPlayer.currentPlayer

내 IDP 정보 조회하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Profile SDK Example'.

import KakaoGameTube

let idpProfile = KGTPlayer.currentPlayer?.idpProfile

시스템 정보


언어 코드 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let languageCode = KGTSystem.languageCode

국가 코드 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let countryCode = KGTSystem.countryCode

IP 기반 국가 코드 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let countryCode = KGTSystem.geoCountryCode

기기 아이디 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let deviceId = KGTSystem.deviceId

기기 모델 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let deviceModel = KGTSystem.deviceModel

OS 이름 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let osName = KGTSystem.osName

네트워크 연결 여부 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let isNetworkConnected = KGTSystem.isNetworkConnected

연결된 네트워크 타입 가져오기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import KakaoGameTube

let networkType = KGTSystem.networkType

카카오 연동 기능


카카오톡 게임 메시지 수신 여부 설정하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import KakaoGameTube
import KakaoGameTubeKakao

// 카카오톡 게임 메시지 수신 여부 설정 뷰 띄우기
KGTKakaoTalk.showSetting { error, isAllowedMe in
	if error.isSuccess {
		// 카카오톡 게임 메시지 수신 여부 설정 성공
		let isAllowedMe = isAllowedMe // 설정된 메시지 수신 허용 여부
	} else if error.code == KGTErrorCode.notKakaoTalkUser {
        // 로그인 한 유저가 '카카오톡' 유저가 아닙니다. 카카오 스토리만 가입한 유저의 계정과 같이 카카오톡 유저가 아닌 경우.
	} else {
		// 카카오톡 게임 메시지 수신 여부 설정 실패
	}
})

카카오톡 프로필 조회하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import KakaoGameTube
import KakaoGameTubeKakao

// 카카오톡 프로필 조회하기
KGTKakaoTalk.talkProfile { error, profile in
	if error.isSuccess {
		// 카카오톡 프로필 조회 성공
		
		let talkProfile = profile // 로그인한 유저의 카카오톡 프로필 정보
    } else if error.code == KGTErrorCode.notKakaoTalkUser {
		// 로그인 한 유저가 '카카오톡' 유저가 아닙니다. 카카오 스토리만 가입한 유저의 계정과 같이 카카오톡 유저가 아닌 경우.
	} else {
		// 카카오톡 프로필 조회 실패
	}
})

카카오톡 게임 친구 목록 조회하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import KakaoGameTube
import KakaoGameTubeKakao

// 게임 친구 목록 조회하기
KGTKakaoTalk.friends { error, players in
	if error.isSuccess {
		// 카카오톡 게임 친구 목록 조회 성공.
		for player in players {
			if let kakaoFriendProfile = player.idpProfile as? KGTKakaoFriendProfile {
			
			}
		}
    } else if error.code == KGTErrorCode.notKakaoTalkUser {
		// 로그인 한 유저가 '카카오톡' 유저가 아닙니다. 카카오 스토리만 가입한 유저의 계정과 같이 카카오톡 유저가 아닌 경우.
	} else {
		// 카카오톡 게임 친구 목록 조회 실패
	}
})

카카오톡 게임 메시지 보내기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import KakaoGameTube
import KakaoGameTubeKakao

// friends API를 통해 가져온 친구 객체
let kakaoProfile: KGTKakaoFriendProfile = // 카카오 프로필 (KGTKakaoFriendProfile 객체)

// [TODO] 템플릿 Id 설정
let templateId = ""

// [TODO] 메시지 템플릿에 설정한 인자 설정
var argumentDic: [String : Any]? = [:]
argumentDic["rog_link"] = "test=100&hello20111"
argumentDic["bruce2"] = "test=100&hello=20111"

// 카카오톡 게임 메시지 보내기
KGTKakaoTalk.sendGameMessage(kakaoProfile: kakaoProfile, templateId: templateId, argumentDic: argumentDic) { error in
	if error.isSuccess {
		// 카카오톡 채팅 메시지 보내기 성공
	} else {
		if error.code == KGTErrorCode.messageSettingDisabled {
			// 받은이가 메시지 수신 거부를 설정한 경우
		} else if error.code == KGTErrorCode.exceedDailyUsage {
			// 한명이 특정 앱에 대해 보낼 수 있는 하루 쿼터(받는 사람 관계없이) 초과시 발생
		} else if error.code == KGTErrorCode.exceedMonthlyUsage {
			// 한명이 특정 앱에 대해 특정인에게 보낼 수 있는 한달 쿼터 초과시 발생
		} else {
			// 카카오톡 채팅 메시지 보내기 실패
		}
	}
})

카카오톡 친구 초대 메시지 전송하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import KakaoGameTube
import KakaoGameTubeKakao

// [TODO] 팝업창으로 띄울지 여부 설정
let isSingle = true

// [TODO] 팝업창으로 띄울지 여부 설정
let isPopup = true
  
// [TODO] 템플릿 Id 설정
let templateId = ""

// [TODO] 메시지 템플릿에 설정한 인자 설정
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 {
		// 카카오톡 초대 메시지 보내기 성공
		for user in users {
			// 유저가 초대 메시지를 전송한 유저 목록 확인
		}
	} else {
		// 전부 실패한 경우(공통된 원인 리턴해주기 필요)
        if error.code == KGTErrorCode.messageSettingDisabled {
			// 받은이가 메시지 수신 거부를 설정한 경우
        } else if error.code == KGTErrorCode.exceedDailyUsage {
			// 한명이 특정 앱에 대해 보낼 수 있는 하루 쿼터(받는 사람 관계없이) 초과시 발생
        } else if error.code == KGTErrorCode.exceedMonthlyUsage {
			// 한명이 특정 앱에 대해 특정인에게 보낼 수 있는 한달 쿼터 초과시 발생
		} else {
			// 카카오톡 초대 메시지 보내기 실패
		}
	}
})

카카오톡 채널 추가하기

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import KakaoGameTube
import KakaoGameTubeKakao

// [TODO] 채널 Id 설정
let channelId = 0

KGTKakaoTalk.addChannel(channelId: channelId) { error in
	if error.isSuccess {
		// 채널 추가 성공
    } else if error.code == KGTErrorCode.notKakaoTalkUser {
		// 로그인 한 유저가 '카카오톡' 유저가 아닙니다. 카카오 스토리만 가입한 유저의 계정과 같이 카카오톡 유저가 아닌 경우.
	} else {
		// 채널 추가 실패
	}
})
  • 레이블 없음