> For the complete documentation index, see [llms.txt](https://pub-star.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pub-star.gitbook.io/docs/1.5.1/ios-sdk/initialize.md).

# Initialize

### initAd()

Initialization PubStar SDK. Initialization must be called once before loading or showing ads.

### Event

`InitAdListenerHandler`

| Callback  | Function                                                 |
| --------- | -------------------------------------------------------- |
| `onDone`  | call when PubStar SDK initializes successfully           |
| `onError` | call when load ad failed. return object type `ErrorCode` |

### Example

```swift
import Pubstar

struct ContentView: View {

    init() {
        PubStarAdManager.getInstance()
            .setInitAdListener(InitAdListenerHandler(
                onDone: {
                    print("PubStar", "onDone")
                },
                onError: { errorCode in
                    print("PubStar", "\(errorCode)")
                }
            ))
            .initAd()
    }


    var body: some View {
        VStack {
            Text("Hello, PubStar's publisher")
        }
    }
}
```
