# Pre-requisite

해당 페이지에서는 Omnitalk SDK를 사용하기 위해서 공통적으로 필요한 내용에 대해서 설명합니다.&#x20;

## 1. SDK 객체 초기화

[콘솔](https://omnitalk.io/console/service/service-id)에서 발급받은 Service Id와 Service Key로 SDK를 초기화 합니다. 해당 정보는 노출되지 않도록 주의하여야 합니다. 초기화된 SDK 객체는 이후 모든 메서드 호출에 사용됩니다.&#x20;

Omnitalk SDK는 싱글톤 패턴으로 제공됩니다. 아래 방법으로 SDK 초기화 및 객체를 얻을 수 있습니다.

```typescript
import OmnitalkSdk

try OmniTalk.sdkInit(serviceId: "YOUR_SERVICE_ID", serviceKey: "YOUR_SERVICE_KEY")
let sdk = OmniTalk.getInstance()
```

## 2. 이벤트 메세지 수신

Event를 수신할 class에서 OmnitalkSdk의 `OmniEventDelegate`를 채택합니다. OmniEventDelegate의 onEvent로 이벤트 메세지를 수신할 수 있습니다. 이벤트 메세지 내용은 [Event Message](https://docs.omnitalk.io/commons/event-message)를 참조 바랍니다.

`OmniEventDeleagte` protocol의 내용은 두 가지 입니다.&#x20;

* `onEvent(eventName: OmniEvent, message: Any)`
* `onClose()`

이벤트 메세지는 Omnitalk SDK에서 제공하는 타입으로 캐스팅하여 사용할 수 있습니다. 다음은 onEvent 이벤트 처리 예시입니다.

```swift
func onEvent(eventName: OmniEvent, message: Any) {
    switch eventName {
        case .LEAVE:
            let leaveEventMsg = message as! EventLeave
            ...
    }    
}
func onClose() {
    ...
}
```
