iOS SDK

iOS에서 게임을 개발하기 위한 GAMEPOT iOS SDK 사용법에 대해 설명합니다. SDK를 설치하고 환경을 구성함으로써 게임과 대시보드를 연동할 수 있습니다.

요구 사양

iOS용 GAMEPOT SDK를 사용하기 위한 요구 사양은 다음과 같습니다.

  • 최소 사양: iOS 15 이상 (하위 버전의 iOS 지원이 필요하면 [email protected] 메일로 문의해 주시기 바랍니다. )

SDK 설치 및 환경 구성

iOS SDK를 설치한 후 환경을 구성하여 GAMEPOT 대시보드와 게임을 연동하고 게임 개발에 필요한 기능을 사용할 수 있습니다.

GAMEPOT SDK에서 지원하는 언어는 아래와 같습니다.

  • 한국어, 영어, 이탈리아어, 태국어 ,베트남어, 일본어, 중국어(간체/번체), 인도네시아어, 독일어, 스페인어, 프랑스어

앱 실행 시 디바이스 언어에 따라 SDK 내 지원 언어로 표기되며 미지원 언어는 영어로 표기됩니다.

SDK 설치

GAMEPOT iOS SDK를 설치하고 프로젝트를 구성하는 방법은 다음과 같습니다.

  1. 관리자 계정으로 대시보드에 로그인해 주세요.

  2. iOS 프로젝트 폴더 내 CocoaPods를 통해 Podfile을 생성해 주세요.

pod init
  1. podfile 파일에 NBase SDK를 추가해 주세요. Podfile 정의 내용은 아래 "Podfile 설정" 항목을 참고하여 주십시오.

  2. NBase SDK를 CocoaPods를 통해 설치해주세요.

pod install

COCOAPODS

iOS SDK의 경우 cocoapods를 설치하셔야만 정상 설치가 가능합니다.

Podfile 설정

편집기로 Podfile을 열어 GAMEPOT SDK에 필요한 프레임워크를 추가합니다.

platform :ios, '15.0'

# 프로젝트 메인 타겟
target '프로젝트 메인 타겟' do
...
  pod 'NBase'
...
end
  • 구글 로그인과 페이스북 로그인을 사용하는 경우

platform :ios, '15.0'

target 'GAMEPOT_GAME' do
 use_frameworks!

 # Pods for Nbase SDK
 pod 'NBase'
 pod 'NBaseAdapterProviderGoogle'
 pod 'NBaseAdapterProviderFacebook'
end
Name
Version
Description
Dependeny modules

NBase

3.0.59

게임팟 기본 모듈

X

NBaseAdapterProviderGoogle

3.0.56

구글 로그인

X

NBaseAdapterProviderFacebook

3.0.57

페이스북 로그인

FBSDKLoginKit (17.4.0)

NBaseAdapterProviderNaver

3.0.57

네이버 로그인

X

NBaseAdapterProviderLine

3.0.57

라인 로그인

X

NBaseAdapterProviderKakao

3.0.56

카카오 로그인

X

NBaseAdapterProviderX

3.0.57

X 로그인

X

이메일, 애플, 게스트 로그인의 경우 기본 모듈에 적용되어 있습니다.

Apollo 패키지 매니저 추가

No such module 'Apollo' 오류 발생 시에 Swift Package Manager 실행 후 Apollo 프레임워크를 추가해 주세요.

  1. Xcode에서 프로젝트 설정으로 이동한 후, Package Dependencies 설정으로 진입해 주십시오.

  1. 우측 상단 url 입력 란에 ' https://github.com/apollographql/apollo-ios.git ' 추가 후 검색하여, apollo-ios 선택 후 Add Package 로 추가해 주십시오.

  2. 노출되는 모달 내 Apollo, ApolloAPI 모듈을 프로젝트의 메인 타겟에 추가해 주십시오.

사전 준비

  1. 프로젝트ID 와 프로젝트 키는 대시보드 → 프로젝트 설정에서 복사 하실 수 있습니다.

  2. 로그인, 스토어, 연동에 대한 환경설정은 모두 대시보드 → 프로젝트 설정 에서 추가/수정 하실 수 있습니다.

  3. 로그인 별로 [로그인 인증 환경 설정] 을 참고하여, 콘솔에 설정하고 대시보드에 추가해야만 합니다.

  4. 인앱 결제 시에 [스토어 환경 설정] 을 참고하여, 콘솔에 설정하고 대시보드에 추가해야만 합니다.

  5. 인앱 결제를 위한 스토어마다 아이템을 등록해 주세요. 대시보드 → 결제 → 인앱에서 추가해 주세요.

초기화

초기화를 수행하려면 게임을 시작할 때 로드되는 첫 장면에 사용되는 개체에 아래 코드를 추가해 주십시오.

import NBase

NBase.initialize([projectId], projectKey: [projectKey], storeId: [storeId], language: [language], region: [region]) { result in
    switch result {
    case .success(let data):
        NBase.showToast(message: data?.encodeToJson() ?? "")
    case .failure(let error):
        NBase.showToast(message: error.errorDescription ?? "")
    }
}
  • Parameter

Key
Type
Description
Required

projectId

String

프로젝트 ID (대시보드 → 프로젝트 설정)

O

projectKey

String

프로젝트 키 (대시보드 → 프로젝트 설정)

O

storeId

String

스토어명 (apple)

O

language

String

언어 (en,ko,jp ...)

O

region

String

리전명 (kr, jp, sg, us, eu, preview)

O

  • Callback

Key
Type
Description

status

Bool

상태

language

String

언어

country

String

국가

remote_ip

String

IP

platform

String

플랫폼

sandbox

Bool

샌드박스 여부

로그인 기능

로그인 기능 사용하기

개발사에서 구현한 로그인 UI에 따라 로그인 버튼을 클릭했을 때 동작하는 SDK 로그인 기능을 사용하려면 아래 코드를 사용해 주십시오.

NBase.signIn(serviceType: .google) { result in
    switch result {
    case .success(let data):
        // signIn Success
        print("signIn Success: \(data)")
        break
    case .failure(let error):
        // signIn failed
        print("signIn Failed: \(error)")
    case .maintenance(let data):
        // maintenance
        /* case 1: Use in-game popup implemented directly by the developer
        case 2: Call the code below to use the SDK's own popup
        NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
            // Popup handling
        }
        */
        print("maintenance: \(data)")
    case .update(let data):
        // update
        /* case 1: Use in-game popup implemented directly by the developer
        case 2: Call the code below to use the SDK's own popup
        NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
            // Popup handling
        }
        */
        print("update: \(data)")
    }
}

업데이트 / 점검 시 SDK 에서 제공하는 자체 팝업을 사용하는 경우 아래 코드를 추가해 주십시오.

NBase.showAppStatusPopup(status: appStatus){ status, e in
    if status.close {
        // App Close
    }                                           
    if status.next{
        // Next, Optional update
    }
}
  • Parameter

Key
Description

SignInServiceType.google

구글

SignInServiceType.anonymous

게스트

SignInServiceType.facebook

페이스북

SignInServiceType.apple

애플

SignInServiceType.kakao

카카오

SignInServiceType.x

X

SignInServiceType.line

라인

SignInServiceType.naver

네이버

SignInServiceType.github

깃헙

SignInServiceType.microsoft

마이크로소프트

SignInServiceType.huawei

화웨이

  • User

Key
Type
Description

id

string

유저의 고유 ID

socialId

string

소셜 ID

name

string

이름 (제공해 주는 경우)

email

string

이메일 (제공해 주는 경우)

token

string

토큰

age

int

나이 (제공해 주는 경우)

profile

string

프로필 (제공해 주는 경우)

customField

string

커스텀 필드

isSignUp

bool

가입 여부

appStatus

AppStatus

점검/업데이트 상태

  • AppStatus

Key
Type
Description

message

string

메시지

startedAt

long

시작 시간

endedAt

long

종료 시간

currentAppVersion

string

현재 앱 버전

updateAppVersion

string

업데이트 앱 버전

currentAppVersionCode

string

현재 앱 버전 코드

updateAppVersionCode

string

업데이트 앱 버전 코드

isForce

bool

강제 업데이트 여부

url

string

점검/업데이트 등록된 URL

SDK 자체 제공 로그인 UI

GAMEPOT SDK가 제공하는 완성된 형태의 로그인 UI를 사용할 수 있습니다. SDK가 제공하는 로그인 UI를 호출하려면 아래 코드를 사용해 주십시오.

NBase.openSignInUI { result in
    switch result {
    case .success(let data):
        // openSignInUI Success
        print("openSignInUI Success: \(data)")
        break
    case .failure(let error):
        // openSignInUI failed
        print("openSignInUI Failed: \(error)")
    case .maintenance(let data):
        // maintenance
        /* case 1: Use in-game popup implemented directly by the developer
        case 2: Call the code below to use the SDK's own popup
        NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
            // Popup handling
        }
        */
        print("maintenance: \(data)")
    case .update(let data):
        // update
        /* case 1: Use in-game popup implemented directly by the developer
        case 2: Call the code below to use the SDK's own popup
        NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
            // Popup handling
        }
        */
        print("update: \(data)")
    }
}

자동 로그인 (옵션)

초기화 한 후에 마지막으로 로그인한 인증 수단으로 자동 로그인을 시도합니다. 자동 로그인 시도 전에 마지막 로그인 Provider 타입 확인을 권장합니다.

// 마지막 로그인 Provider 타입 확인
let lastProviderType = NBase.getLastProviderType()

if lastProviderType != .none {
    // 마지막 로그인 정보가 있는 경우에만 자동 로그인 시도
    NBase.signInLastLoggedIn(completionHandler: { result in
        switch result {
        case .success(let data):
            // signInLastLoggedIn Success
            print("signInLastLoggedIn Success: \(data)")
        case .failure(let error):
            // signInLastLoggedIn failed
            print("signInLastLoggedIn Failed: \(error)")
        case .maintenance(let data):
            /* maintenance
            case 1: Use in-game popup implemented directly by the developer
            case 2: Call the code below to use the SDK's own popup
            NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
                // Popup handling
            }
            */
            print("maintenance: \(data)")
        case .update(let data):
            /* update
            case 1: Use in-game popup implemented directly by the developer
            case 2: Call the code below to use the SDK's own popup
            NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
                // Popup handling
            }
            */
            print("update: \(data)")
        }
    })
} else {
    print("No last login provider found")
}

getLastProviderType() 메서드는 마지막으로 로그인한 Provider 타입을 반환합니다.

signInLastLoggedIn() 메서드는 마지막으로 로그인한 인증 수단으로 자동 로그인을 시도합니다.

  • Callback

Key
Type
Description

data

NBUser

로그인 성공 시 사용자 정보

error

NBaseError

로그인 실패 시 에러 정보

로그아웃

SDK 로그아웃 기능을 사용하려면 아래 코드를 사용해 주십시오.

NBase.signOut() { result in
    switch result {
    case .success(let status):
        // signOut Success
        print("signOut Success: \(status ?? false)")
    case .failure(let error):
        // signOut Failed
        print("signOut Failed: \(error.errorCode), \(error.errorDescription ?? "")")
    }
}
  • Callback

Key
Type
Description

status

Bool

성공 여부

회원탈퇴

SDK 회원탈퇴 기능을 사용하려면 아래 코드를 사용해 주십시오.

NBase.deleteMember() { result in
    switch result {
    case .success(let status):
        // deleteMember Success
        print("deleteMember Success: \(status ?? false)")
    case .failure(let error):
        // deleteMember Failed
        print("deleteMember Failed: \(error.errorCode), \(error.errorDescription ?? "")")
    }
}
  • Callback

Key
Type
Description

status

Bool

성공 여부

자체 아이디 비밀번호 인증하기 (옵션)

사용자가 이메일 주소와 비밀번호를 사용하여 로그인할 수 있게 하는 인증 메서드입니다. 사용자의 이메일 주소와 비밀번호를 기반으로 사용자 인증을 수행합니다. 이 기능은 전통적인 이메일/비밀번호 기반의 인증 시스템에서 중요한 역할을 합니다.

NBase.signInWithPassword(username: [username], password: [password], options: [option]) { result in
    switch result {
    case .success(let user):
        NBase.showToast(message: user?.encodeToJson() ?? "")
    case .failure(let error):
        NBase.showToast(message: error.errorDescription ?? "")
    }
}

자격 증명으로 로그인하기 (옵션)

외부에서 획득한 소셜 계정의 자격 증명(Access Token)을 사용하여 로그인하려면 아래 코드를 사용해 주십시오.

NBase.signInWithCredential(providerId: providerId, accessToken: accessToken, options: options) { result in
    switch result {
    case .success(let data):
        // signInWithCredential Success
        print("signInWithCredential Success: \(data)")
    case .failure(let error):
        // signInWithCredential Failed
        print("signInWithCredential Failed: \(error.errorCode), \(error.errorDescription ?? "")")
    case .maintenance(let data):
        /* maintenance
        case 1: Use in-game popup implemented directly by the developer
        case 2: Call the code below to use the SDK's own popup
        NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
            // Popup handling
        }
        */
        print("maintenance: \(data)")
    case .update(let data):
        /* update
        case 1: Use in-game popup implemented directly by the developer
        case 2: Call the code below to use the SDK's own popup
        NBase.showAppStatusPopup(status: (data?.appStatus)) { status, e in
            // Popup handling
        }
        */
        print("update: \(data)")
    }
}
  • Parameter

Key
Type
Description
Required

providerId

String

Provider ID (예: "google", "facebook" 등)

O

accessToken

String

소셜 계정의 Access Token

O

options

String

추가 옵션 (선택사항)

X

  • Callback

Key
Type
Description

data

NBUser

로그인 성공 시 사용자 정보

error

NBaseError

로그인 실패 시 에러 정보

외부 계정 연동 기능

외부 계정 연동 기능 사용하기

현재 게임팟 사용자 계정에 다른 소셜 계정을 연동하려면 아래 코드를 사용해 주십시오.

NBase.createLinking(serviceType: .google) { result in
    switch result {
    case .success(let linkingId):
        // createLinking Success
        print("createLinking Success: \(linkingId ?? "")")
        // 계정 연동 성공 후 처리 로직
    case .failure(let error):
        // createLinking Failed
        print("createLinking Failed: \(error.errorCode), \(error.errorDescription ?? "")")
    }
}
  • Parameter

Key
Type
Description
Required

serviceType

SignInServiceType

연동할 Provider 타입 (예: .google, .facebook 등)

O

  • Callback

Key
Type
Description

linkingId

String

연동 성공 시 반환되는 연동 ID

연동 리스트 확인

현재 게임팟 사용자 계정에 연동된 소셜 계정 목록을 확인하려면 아래 코드를 사용해 주십시오.

NBase.getLinkedLists() { result in
    switch result {
    case .success(let linkings):
        // getLinkedLists Success
        print("getLinkedLists Success: \(linkings)")
        // 연동 목록 확인 후 처리 로직
    case .failure(let error):
        // getLinkedLists Failed
        print("getLinkedLists Failed: \(error.errorCode), \(error.errorDescription ?? "")")
    }
}
  • Callback

Key
Type
Description

linkings

Array

연동된 계정 목록

  • Linking

Key
Type
Description

id

String

연동 ID (계정 연동 해제 시 사용)

username

String

소셜 ID

provider

String

소셜 provider 타입

연동 해제

현재 게임팟 사용자 계정에서 특정 소셜 계정 연동을 해제하려면 아래 코드를 사용해 주십시오.

NBase.deleteLinking(linkingId: linkingId) { result in
    switch result {
    case .success(let status):
        // deleteLinking Success
        print("deleteLinking Success: \(status ?? false)")
        // 연동 해제 성공 후 처리 로직
    case .failure(let error):
        // deleteLinking Failed
        print("deleteLinking Failed: \(error.errorCode), \(error.errorDescription ?? "")")
    }
}
  • Parameter

Key
Type
Description
Required

linkingId

String

해제할 연동 ID (createLinking 또는 getLinkedLists에서 획득)

O

  • Callback

Key
Type
Description

status

Bool

성공 여부

앱 상태 확인

현재 클라이언트의 점검 / 업데이트 상태를 확인하려면 아래 코드를 사용해 주십시오.

NBase.checkAppStatus() { status in
    switch status {
        case .success(let data):
        if let data = data {
            switch data {
                case .maintenance(let maintenance):
                    // Maintenance
                    /* case 1: Use in-game popup implemented directly by the developer
                    case 2: Call the code below to use the SDK's own popup
                    NBase.showAppStatusPopup(status: data) { status, e in
                        // Popup handling
                    }
                    */
                case .update(let update):
                    // Update
                    /* case 1: Use in-game popup implemented directly by the developer
                    case 2: Call the code below to use the SDK's own popup
                    NBase.showAppStatusPopup(status: data) { status, e in
                        // Popup handling
                    }
                    */
                }
            } else {
                // AppStatus Success
                print("checkAppStatus success")

문제해결

Q. Authorization failed: Error Domain=AKAuthenticationError Code=-7026 A. TARGETS > +Capability 를 클릭하여 Sign in with Apple 을 추가합니다.

Last updated