# 초기화하기

Wepin widget iOS SDK를 초기화하는 방법입니다.&#x20;

먼저 위핀 인스턴스를 생성하고 앱 등록 후 할당 받은 앱 ID와 앱 키를 이용하여 인스턴스를 초기화 합니다.

## 초기화하기

생성된 인스턴스를 사용하기 전에 앱  ID와 앱 키를 이용하여 초기화를 합니다.&#x20;

<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

초기화에 사용되는 파라미터 <mark style="color:blue;">`WidgetAttributes`</mark> 와 <mark style="color:blue;">`WidgetType`</mark> 아래와 같이 정의되어 있습니다.

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

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

* **appId**: *String*\
  앱 등록시 할당 받은 ID
* **appKey**: *String*\
  앱 등록시 할당 받은 키 값
* **attributes**: *Object (optional)*\
  위핀 위젯의 속성 값
  * **type**: *WidgetType*\
    처음 로딩 시 앱 위젯 윈도우를 어떻게 보여줄 지를 결정 합니다. 기본\
    값은 `hide` 입니다. \
    `show`: 처음 로딩 후, 바로 위젯 윈도우를 띄워서 보여 줍니다. \
    `hide`: 는 처음 로딩시 위젯 윈도우를 보여주지 않고 숨깁니다. 이후 `openWidget()`을 통해서 위젯을 띄워 보여 줍니다.
  * **defaultLanguage**: *String*\
    위젯 기본 언어 설정, 기본 값은 `ko`입니다. 현재 지원하는 언어는 `en`, `ko` 이렇게 2가지 입니다.
  * **defaultCurrency:** *String*\
    위젯 기본 통화 설정, 기본 값은 `KRW`입니다. 현재 지원하는 통화는 `USD`, `KRW` 이렇게 2가지 입니다.

### Universal Link 처리하기

앱의 Info 파일에서 추가한 URL schemes 값을 AppDelegate 또는 SceneDelegate에서 처리해야 합니다. 앱에 SceneDelegate가 있으면 SceneDelegate  에서 처리하고, 없으면 AppDelegate 에서 아래와 같이 처리하는 코드를 추가 합니다.&#x20;

<pre class="language-swift"><code class="lang-swift"><strong>
</strong><strong>// AppDelegate에 추가하는 경우에는 
</strong><strong>// func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool{ }
</strong><strong>// 에서 처리 
</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”
    // url scheme 체크
    guard url.scheme == checkScheme else {
      print(“invalid url scheme : ” + url.scheme!)
      return
    }
    // 받은 url을 wepin에 넘겨준다
    Wepin.instance().handleUniversalLink(paramUrl: url)
    //
}
</code></pre>

## isInitialized

<mark style="color:blue;">`isInitialized`</mark>메서드를 이용해서 Wepin 인스턴스가 정상적으로 초기화 되었는지 확인할 수 있습니다. &#x20;

반환값은 아래와 같습니다.&#x20;

* *boolean*\
  init 결괏값, init이 정상적으로 잘 된 경우 <mark style="color:orange;">`true`</mark> 실패한 경우 <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/deprecated/ios-swift-sdk/initialization.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.
