# The Onside Delegate

`OnsideDelegate` lets you tune how OnsideKit presents its screens and routes login. Every method has a default implementation, so implement only the ones you need.

```swift
protocol OnsideDelegate: AnyObject {
    @MainActor func onside(hostWindowSceneForScreen screen: OnsideScreen) -> UIWindowScene?
    @MainActor func onside(uiThemeOverrideForScreen screen: OnsideScreen) -> OnsideUIThemeMode?
    @MainActor func onsideShouldForceLocalLoginMethods() -> Bool
    @MainActor func onsideDefaultCountryCodeAssumption() -> String?
}
```

Assign your delegate (keep a strong reference — it's held weakly), typically at launch:

```swift
@main
final class AppDelegate: UIResponder, UIApplicationDelegate, OnsideDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        Onside.initialize()
        Onside.delegate = self
        return true
    }
}
```

## OnsideScreen

Several delegate methods receive the screen OnsideKit is about to present:

```swift
enum OnsideScreen {
    case login                   // the user authentication screen
    case paymentMethodsManager   // the saved-cards management screen
    case profileInfoFulfillment  // a step that collects/confirms profile info (e.g. region) during a purchase
    case purchase                // the purchase flow
}
```

## Host window scene

```swift
func onside(hostWindowSceneForScreen screen: OnsideScreen) -> UIWindowScene?
```

Return the `UIWindowScene` in which OnsideKit should present the given screen — useful in multi-window apps. If you return `nil` (the default), OnsideKit uses the first active connected scene.

```swift
func onside(hostWindowSceneForScreen screen: OnsideScreen) -> UIWindowScene? {
    return preferredScene   // or nil to use the default
}
```

{% hint style="warning" %}
If no connected window scene is available, OnsideKit cannot present its UI and the screen is not shown.
{% endhint %}

## Per-screen theme override

```swift
func onside(uiThemeOverrideForScreen screen: OnsideScreen) -> OnsideUIThemeMode?
```

Force a theme for a specific screen, overriding the [global theme](/sdk/customization/appearance.md) and the system appearance:

* `.light` / `.dark` — force that theme
* `.auto` — follow the system setting
* `nil` (default) — no override; fall back to the global theme, then the system theme

```swift
func onside(uiThemeOverrideForScreen screen: OnsideScreen) -> OnsideUIThemeMode? {
    screen == .login ? .dark : nil
}
```

## Force in-SDK login

```swift
func onsideShouldForceLocalLoginMethods() -> Bool
```

By default OnsideKit prefers the app-to-app login via the Onside store app. Return `true` to always use OnsideKit's own in-app login screen instead. It is purely a UI-routing switch — it doesn't change which credentials are accepted. Default: `false`. See [Authentication & User Account](/sdk/core-concepts/authentication.md).

## Pre-login region hint

```swift
func onsideDefaultCountryCodeAssumption() -> String?
```

Provide an ISO 3166-1 alpha-2 country code (e.g. `"US"`, `"DE"`) to use as the region **before** the user logs in, improving logged-out pricing and availability. Return `nil` (default) to use the device region. Once the user logs in, the account's region is used and this hint is ignored. See [Regions & Storefronts](/sdk/products-and-subscriptions/regions-and-storefronts.md).


---

# 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.onside.io/sdk/customization/delegate.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.
