# iOS SDK

## System Requirements <a href="#undefined" id="undefined"></a>

The following are the system requirements for using the GAMEPOT iOS SDK:

* Minimum requirement: iOS 15 or higher (If support for lower iOS versions is needed, please contact <dl_help_game@navercorp.com>.)

## SDK Installation and Environment Configuration <a href="#sdk" id="sdk"></a>

After installing the iOS SDK, configure the environment to integrate the GAMEPOT dashboard with the game and use the necessary features for game development.

The languages supported by the GAMEPOT SDK are as follows:

* Korean, English, Italian, Thai, Vietnamese, Japanese, Chinese (Simplified/Traditional), Indonesian, German, Spanish, French.

When the app is run, the supported language will be displayed according to the device's language. If a language is not supported, it will default to English.

### SDK Installation <a href="#sdk" id="sdk"></a>

To install the GAMEPOT iOS SDK and set up the project, follow these steps

1. Log in to the dashboard with an administrator account.
2. In the iOS project folder, create a Podfile using CocoaPods.

```terminal
pod init
```

3. Add the NBase SDK to the Podfile.\
   Please refer to the "Podfile Configuration" section below for the Podfile definitions.
4. Install the NBase SDK via CocoaPods.

```terminal
pod install
```

> **COCOAPODS**
>
> For the iOS SDK, you must install [CocoaPods](https://cocoapods.org/) for a successful installation.

### **Podfile** Configuration

Open the Podfile with a text editor and add the necessary frameworks for the GAMEPOT SDK.

```xml
platform :ios, '15.0'

# Project Main Target
target 'Project Main Target' do
...
  pod 'Alamofire', '5.8.1'
  pod 'Apollo', '1.14.1'
  pod 'Socket.IO-Client-Swift', '16.1.0'
  pod 'AppAuth', '1.6.2'
  pod 'SDWebImage', '5.19.1'
  pod 'NBase', '3.0.51'
...
end
```

Example: If using Google login and Facebook login.

<pre class="language-xml"><code class="lang-xml">platform :ios, '15.0'

<strong>target 'GAMEPOT_GAME' do
</strong> use_frameworks!

 # Pods for Nbase SDK
 pod 'Alamofire', '5.8.1'
 pod 'Apollo', '1.14.1'
 pod 'Socket.IO-Client-Swift', '16.1.0'
 pod 'AppAuth', '1.6.2'
 pod 'SDWebImage', '5.19.1'
 pod 'NBase', '3.0.51'
 pod 'NBaseAdapterProviderGoogle', '3.0.1'
 pod 'NBaseAdapterProviderFacebook', '3.0.51'
end
</code></pre>

<table><thead><tr><th width="289">Name</th><th width="86">Version</th><th width="146">Type</th><th>Dependeny modules</th></tr></thead><tbody><tr><td>NBase</td><td>3.0.51</td><td><strong>GAMEPOT Base Module</strong></td><td>X</td></tr><tr><td>NBaseAdapterProviderGoogle</td><td>3.0.1</td><td>Google Login</td><td></td></tr><tr><td>NBaseAdapterProviderFacebook</td><td>3.0.51</td><td>Facebook Login</td><td>FBSDKLoginKit (16.3.1)</td></tr><tr><td>NBaseAdapterProviderNaver</td><td>3.0.1</td><td>NAVER Login</td><td></td></tr><tr><td>NBaseAdapterProviderLine</td><td>3.0.1</td><td>Line Login</td><td></td></tr><tr><td>NBaseAdapterProviderX</td><td>3.0.1</td><td>X Login</td><td></td></tr></tbody></table>

For email, Apple, and guest logins, they are applied to the base module.

> **Adding Apollo Package Manager**
>
> If the error "No such module 'Apollo'" occurs, please run the Swift Package Manager and add the Apollo framework.

<figure><img src="/files/IeBcvf6duXbyaI9OmnfC" alt=""><figcaption></figcaption></figure>

Click the '+' button, then add the package collection '<https://github.com/apollographql/apollo-ios.git>', select apollo-ios, and then choose the main project target in the Add Package section.

<figure><img src="/files/gESMHmeSlsXzum5FzpAU" alt=""><figcaption></figcaption></figure>

## Preparation <a href="#undefined" id="undefined"></a>

1. You can copy the Project ID and Project Key from the Dashboard → Project Settings.&#x20;
2. Environment settings for login, store, and integration can all be added/modified from the Dashboard → Project Settings.&#x20;
3. For each login method, refer to the \[[Login Authentication Settings](/basics/gamepot-3.0/images-and-media/editor/login-authentication-settings.md)], configure it in the console, and add it to the dashboard.&#x20;
4. For in-app payments, refer to the \[[Store Settings](/basics/gamepot-3.0/images-and-media/editor/store-settings.md)], configure it in the console, and add it to the dashboard.&#x20;
5. Please register items for in-app payments in each store. Add them in the Dashboard → Payment → In-App section.

## Initialization <a href="#undefined" id="undefined"></a>

To initialize, add the following code to the object used in the first scene that loads when the game starts.

{% tabs %}
{% tab title="Swift" %}

```swift
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 ?? "")
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared initialize:[projectId] projectKey:[projectKey] storeId:[storeId] language:[language] region:[region] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Initialization Error: %@", error.localizedDescription);
    } else {
        NSLog(@"Initialization succeeded with result: %@", result);
    }
}];
```

{% endtab %}
{% endtabs %}

* Parameter

<table><thead><tr><th width="221">Key</th><th width="338">Description</th><th>Required</th></tr></thead><tbody><tr><td>projectId</td><td>Dashboard → Project Settings</td><td>O</td></tr><tr><td>projectKey</td><td>shboard → Project Settings</td><td>O</td></tr><tr><td>storeId</td><td>Store (apple, google)</td><td>O</td></tr><tr><td>language</td><td>Language (en,ko,jp ...)</td><td>O</td></tr><tr><td>region</td><td>Region (kr, jp, sg, us, eu, preview)</td><td>O</td></tr></tbody></table>

* Callback

| Key        | Type   | Description    |
| ---------- | ------ | -------------- |
| status     | Bool   | Status         |
| language   | String | Language       |
| country    | String | Country        |
| remote\_ip | String | IP             |
| platform   | String | Platform       |
| sandbox    | Bool   | Sandbox Status |

## Login <a href="#undefined" id="undefined"></a>

To use the SDK login functionality that is triggered when the login button is clicked, depending on the login UI implemented by the developer, please use the following code.

{% tabs %}
{% tab title="Swift" %}

```swift
NBase.signIn(serviceType: .google) { result in
    switch result {
    case .success(let data):
        NBase.showToast(message: data?.encodeToJson() ?? "")
        break
    case .failure(let error):
        if let nBaseError = error as? NBaseError {
            switch nBaseError {
            case .noMaintenance:  // Maintenance
                NBase.showToast(message: error.localizedDescription)
            case .noUpdated : // Update
                NBase.showToast(message: error.localizedDescription)
            default:
                print("An unknown error occurred: \(error)")
                NBase.showToast(message: error.localizedDescription)
            }
        } else {
            print("An error occurred: \(error)")
            NBase.showToast(message: error.localizedDescription)
        }
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared signIn:serviceType :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"signIn Error: %@", error.localizedDescription);
    } else {
        NSLog(@"signIn succeeded with result: %@", result);
    }
}];
```

{% endtab %}
{% endtabs %}

* Parameter

| Key                         | Description |
| --------------------------- | ----------- |
| SignInServiceType.google    | Google      |
| SignInServiceType.anonymous | Guest       |
| SignInServiceType.facebook  | Facebook    |
| SignInServiceType.apple     | Apple       |
| SignInServiceType.kakao     | Kakao       |
| SignInServiceType.x         | X           |
| SignInServiceType.line      | Line        |
| SignInServiceType.naver     | NAVER       |
| SignInServiceType.github    | Github      |
| SignInServiceType.microsoft | Microsoft   |
| SignInServiceType.huawei    | Huawei      |

* Callback

| Key      | Type   | Description   |
| -------- | ------ | ------------- |
| id       | String | User ID       |
| name     | String | User Name     |
| nickname | String | User Nickname |
| email    | String | Email         |
| token    | String | Token         |
| age      | Int    | Age           |
| birth    | String | Date of Birth |
| sex      | String | Gender        |
| profile  | String | Profile URL   |
| mobile   | String | Phone Number  |

#### Automatic Login (Optional)

After initialization, the system attempts automatic login using the last authentication method the user logged in with.

{% tabs %}
{% tab title="Swift" %}

```swift
NBase.signInLastLoggedIn(completionHandler: { result in
    switch result {
    case .success(let data):
        NBase.showToast(message: data?.encodeToJson() ?? "")
    case .failure(let error):
        NBase.showToast(message: error.errorDescription ?? "")
    }
})
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared signInLastLoggedIn:^(NSDictionary * _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"signInLastLoggedIn Error: %@", error.localizedDescription);
    } else {
        NSLog(@"signInLastLoggedIn succeeded with result: %@", result);
    }
}];
```

{% endtab %}
{% endtabs %}

#### Self-ID and Password Authentication (Optional)

This authentication method allows users to log in using their email address and password. It performs user authentication based on the user's email address and password. This feature plays an important role in traditional email/password-based authentication systems.

{% tabs %}
{% tab title="Swift" %}

```swift
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 ?? "")
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared signInWithPassword:[username] password:[password] options:[options] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"signInWithPassword Error: %@", error.localizedDescription);
    } else {
        NSLog(@"signInWithPassword succeeded with result: %@", result);
    }
}];
```

{% endtab %}
{% endtabs %}

## Logout

To use the SDK logout function, please use the code below.

{% tabs %}
{% tab title="Swift" %}

```swift
NBase.signOut() { result in
    switch result {
    case .success(let status):
        NBase.showToast(message: "signOut \((status != nil) ? "true" : "false")")
    case .failure(let error):
        NBase.showToast(message: error.errorDescription ?? "")
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared signOut:^(NSNumber *result, NSError *error) {
    if (error) {
        NSLog(@"signOut Error: %@", error.localizedDescription);
    } else {
        NSLog(@"signOut: %@", result.boolValue ? @"YES" : @"NO");
    }
}];
```

{% endtab %}
{% endtabs %}

* Callback

| Key    | Type | Description    |
| ------ | ---- | -------------- |
| status | Bool | Success Status |

## Payment <a href="#undefined" id="undefined"></a>

Before making a payment, you must configure the settings for each store according to the store's requirements in the \[[Store Settings](/basics/gamepot-3.0/images-and-media/editor/store-settings.md)].

Additionally, if items have not been added in the Dashboard → Payment → In-App section, the error 'ProductID not found' will occur.

### Fetch In-App Information

When making a payment, you need to display payment information and local currency details on the screen. You can retrieve the current payment currency, name, and other details using the functions below. If the information is not fetched correctly, please check the console settings.

{% tabs %}
{% tab title="Swift" %}

```swift
let products = NBase.getProductItems()
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared getProductItems:^(NSString * _Nullable result) {
    NSLog(@"getProductItems result: %@", result);
}];
```

{% endtab %}
{% endtabs %}

* Callback

| Key            | Type    | Description         |
| -------------- | ------- | ------------------- |
| id             | String  | Product ID          |
| name           | String  | Product Name        |
| currency       | String  | Currency            |
| price          | Float64 | Product Price       |
| localizedPrice | String  | Localized Price     |
| description    | String  | Product Description |

### Payment Request

You can request a payment using the `productId` from the fetched in-app information.

{% tabs %}
{% tab title="Swift" %}

```swift
NBase.purchase(productId: [productId], metadata: [metadata], options: [options]) { result in
    switch result {
    case .success(let data):
        NBase.showToast(message: data?.encodeToJson() ?? "")
    case .failure(let error):
        NBase.showToast(message: error.errorDescription ?? "")
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[NBaseBridge.shared purchase:[productId] metadata:[metadata] options:[options] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"purchase Error: %@", error.localizedDescription);
    } else {
        NSLog(@"purchase succeeded with result: %@", result);
    }
}];
```

{% endtab %}
{% endtabs %}

* Parameter

<table><thead><tr><th width="191">Key</th><th width="370">Description</th><th>Required</th></tr></thead><tbody><tr><td>productId</td><td>Product ID (Dashboard → Payment → IAP)</td><td>O</td></tr><tr><td>metadata</td><td>Metadata</td><td>X</td></tr><tr><td>options</td><td>결Payment Option Features</td><td>X</td></tr></tbody></table>

* Callback

| Key       | Type    | Description         |
| --------- | ------- | ------------------- |
| orderId   | String  | Order ID            |
| receipt   | String  | Receipt             |
| signature | String  | Signature           |
| productId | String  | Product ID          |
| storeId   | String  | Store ID            |
| country   | String  | Country             |
| quantity  | Int     | Quantity            |
| paymentId | String  | Payment ID          |
| currency  | String  | Currency            |
| serverId  | String  | Server ID           |
| playerId  | String  | Player ID           |
| userdata  | String  | User Data           |
| metadata  | String  | Metadata            |
| options   | String  | Payment Options     |
| authCode  | String  | Authentication Code |
| level     | Int     | Level               |
| price     | Float64 | Price               |

## Troubleshooting <a href="#undefined" id="undefined"></a>

Q. Authorization failed: Error Domain=AKAuthenticationError Code=-7026 A. Click on TARGETS > +Capability to add Sign in with Apple.

<figure><img src="/files/o1arX8FZWb64odxxuKls" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gamepot.io/basics/gamepot-3.0/images-and-media/editor/ios-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
