# Initialization

Here is how to initialize the Wepin widget iOS SDK.

Then, use the App ID and App Key assigned after app registration to initialize the instance.

## Initialize

Before using the created instance, initialize it using the App ID and App Key.

<pre class="language-swift"><code class="lang-swift"><strong>import wepin
</strong><strong>
</strong><strong>let appId = "app_id_eg12sf3491azgs520"
</strong>let appKey = "ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313", 
let attributes = Wepin.WidgetAttributes(type: Wepin.WidgetType.show)

let attributes = Wepin.WidgetAttributes(type: Wepin.WidgetType.show)
let wepin = Wepin.instance()
wepin.initialize(appId: appId, appKey: appKey, attributes: attributes){ (result, error) -> Void in
    print(result)
}
</code></pre>

### `WidgetAttributes`, `WidgetType`

The <mark style="color:blue;">`WidgetAttributes`</mark> and <mark style="color:blue;">`WidgetType`</mark>, which are used as parameters for initialization, are as follows.

```java
public enum WidgetType: String {
    case show
    case hide
}

public struct WidgetAttributes {
    var type: WidgetType
    var defaultLanguage: String
    var defaultCurrency: String
}
```

* **`appId`**: *String*\
  App ID assigned during registration
* **`appKey`**: *String*\
  App Key assigned during registration
* **`attributes`**: *Object (optional)*\
  Properties of the Wepin Widget
  * **`type`**: *WidgetType*\
    It determines how the app widget window will be displayed on initial loading. The default value is <mark style="color:blue;">`hide`</mark>. \
    `show`: Show the widget window immediately after loading for the first time.\
    `hide`: Hide the widget window initially when loading and show it later using <mark style="color:blue;">`openWidget()`</mark>.
  * **`defaultLanguage`**: *String*\
    The language to be displayed on the widget. The default value is <mark style="color:blue;">`ko`</mark>. The currently supported languages are <mark style="color:blue;">`en`</mark> and <mark style="color:blue;">`ko`</mark>.
  * **`defaultCurrency`:** *String*\
    The currency to be displayed on the widget. The default value is <mark style="color:blue;">`KRW`</mark>. The currently supported currencies are <mark style="color:blue;">`USD`</mark> and <mark style="color:blue;">`KRW`</mark>.

### Handle Universal Link

You need to handle the URL schemes added in the app's Info file in the AppDelegate or SceneDelegate. If your app has SceneDelegate, handle it there. Otherwise, add the following code to handle it int the AppDelegate.&#x20;

<pre class="language-swift"><code class="lang-swift"><strong>
</strong><strong>// If you are adding it to AppDelegate, handle it here:
</strong><strong>// func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool{ } 
</strong><strong>
</strong><strong>func scene(_ scene: UIScene, openURLContexts URLContexts: Set&#x3C;UIOpenURLContext>) {
</strong>
    guard let url = URLContexts.first?.url else { return }
    let bundleId = Bundle.main.infoDictionary?[“CFBundleIdentifier”] as! String
    print(“bundleId ” + bundleId)
    let checkScheme = bundleId + “.wepin”
    // Check url scheme
    guard url.scheme == checkScheme else {
      print(“invalid url scheme : ” + url.scheme!)
      return
    }
    // Pass the received URL to Wepin.
    Wepin.instance().handleUniversalLink(paramUrl: url)
    //
}
</code></pre>

## `isInitialized`

You can use the <mark style="color:blue;">`isInitialized`</mark> method to check if the Wepin instance has been initialized successfully.

The returned value is as follows.

* *boolean*\
  init result; <mark style="color:orange;">`true`</mark> if Wepin SDK is already initialized, otherwise <mark style="color:orange;">`false`</mark>.

```swift
if(Wepin.isInitialized()) {
    // Success to initialize wepin
}
```


---

# 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.wepin.io/en/deprecated/ios-swift-sdk/init.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.
