> For the complete documentation index, see [llms.txt](https://multiset.gitbook.io/multiset/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://multiset.gitbook.io/multiset/native-support/ios-swift-native/sample-views/landingview.md).

# LandingView

## Overview

The `LandingView` serves as the entry point for the MultiSet SDK demo application. It demonstrates SDK initialization, authentication handling, and navigation to the AR localization view.

## Description

This SwiftUI view is responsible for:

1. Initializing the MultiSet SDK with credentials
2. Handling the authentication flow
3. Allowing users to select localization mode (Single-Frame or Multi-Frame)
4. Navigating to the AR localization session
5. Displaying configured object codes and navigating to the object tracking session

***

## Authentication Flow

### 1. SDK Initialization

The SDK is initialized using credentials from `SDKConfig`:

```swift
// Build config from SDKConfig
var config = SDKConfig.buildConfig()
config.localizationMode = selectedMode  // Override with UI selection

// Initialize SDK
MultiSet.shared.initialize(config: config, callback: sdkDelegate)
```

### 2. Configuration Options

Configuration is built using `MultiSetConfig`:

| Property                 | Description                                        |
| ------------------------ | -------------------------------------------------- |
| `clientId`               | Your client identifier                             |
| `clientSecret`           | Your secret key                                    |
| `mapCode`                | Single map code for localization                   |
| `mapSetCode`             | MapSet code for localizing against multiple maps   |
| `localizationMode`       | `.singleFrame` or `.multiFrame`                    |
| `meshVisualization`      | Enable/disable 3D mesh overlay visualization       |
| `backgroundLocalization` | Enable/disable background localization             |
| `objectCodes`            | Array of object codes to track                     |
| `autoObjectTracking`     | Enable/disable auto object tracking on view appear |

### 3. Authentication Callbacks

The view uses `MultiSetSDKDelegate` (implementing `MultiSetCallback`) to receive authentication events:

```swift
func onSDKReady() {
    // SDK is initialized, authentication in progress
}

func onAuthenticationSuccess() {
    // Authentication successful, ready for localization
    // Enable localization button
}

func onAuthenticationFailure(error: String) {
    // Authentication failed
    // Show error message
}
```

***

## APIs Used for Authentication

### MultiSet

| Method                                         | Description                                                                                                                                                                                                                      |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MultiSet.shared.initialize(config:callback:)` | Initializes the SDK with configuration and callback                                                                                                                                                                              |
| `MultiSet.shared.setLocalizationMode(_:)`      | Updates the localization mode at runtime                                                                                                                                                                                         |
| `MultiSet.shared.updateConfig(_:)`             | Applies an updated configuration to the running SDK before the next query (see [Updating Configuration at Runtime](/multiset/native-support/ios-swift-native/api-reference/multisetconfig.md#updating-configuration-at-runtime)) |
| `MultiSet.shared.isInitialized`                | Check if SDK is initialized                                                                                                                                                                                                      |
| `MultiSet.shared.isAuthenticated`              | Check if authentication succeeded                                                                                                                                                                                                |

### MultiSetConfig

| Property                 | Type               | Description                                     |
| ------------------------ | ------------------ | ----------------------------------------------- |
| `clientId`               | `String`           | Client identifier for authentication            |
| `clientSecret`           | `String`           | Secret key for authentication                   |
| `mapCode`                | `String`           | Sets the map code for single-map localization   |
| `mapSetCode`             | `String`           | Sets the mapSet code for multi-map localization |
| `localizationMode`       | `LocalizationMode` | Sets `.singleFrame` or `.multiFrame` mode       |
| `meshVisualization`      | `Bool`             | Enables mesh visualization after localization   |
| `backgroundLocalization` | `Bool`             | Enables background localization                 |

***

## UI Components

### Cards

The landing screen has two feature cards:

**Localization Card**

* Displays the active map code (from `SDKConfig`)
* Mode picker: Single Frame / Multi Frame
* **Start Localization** button — navigates to `ARLocalizationView`

**Object Tracking Card**

* Displays the count of configured object codes
* Scrollable list of object code badges
* **Start Object Tracking** button — navigates to `ARObjectTrackingView`

Both buttons are disabled until authentication succeeds.

### Configuration (Settings) Screen

A **gear icon** in the navigation bar opens a full-screen **Configuration** screen (`SettingsView`) that edits the Map / MapSet localization and object-tracking behavior at runtime. It is backed by a `ConfigStore` that persists values across launches via `UserDefaults`, and on **Save** / **Reset** it calls `MultiSet.shared.updateConfig(_:)` so the changes apply to the running SDK **before the next query** — no relaunch required. See [Updating Configuration at Runtime](/multiset/native-support/ios-swift-native/api-reference/multisetconfig.md#updating-configuration-at-runtime).

### State Properties

| Property                   | Type                  | Description                                   |
| -------------------------- | --------------------- | --------------------------------------------- |
| `sdkDelegate`              | `MultiSetSDKDelegate` | ObservableObject that handles SDK callbacks   |
| `navigateToAR`             | `Bool`                | Controls navigation to `ARLocalizationView`   |
| `navigateToObjectTracking` | `Bool`                | Controls navigation to `ARObjectTrackingView` |
| `selectedMode`             | `LocalizationMode`    | Currently selected localization mode          |
| `showToast`                | `Bool`                | Controls toast message visibility             |

***

## Callbacks (MultiSetCallback Protocol)

### onSDKReady()

Called when the SDK has been initialized and is beginning authentication.

```swift
func onSDKReady() {
    DispatchQueue.main.async {
        self.isSDKReady = true
        self.statusText = "SDK ready, authenticating..."
    }
}
```

### onAuthenticationSuccess()

Called when authentication with the MultiSet backend is successful.

```swift
func onAuthenticationSuccess() {
    DispatchQueue.main.async {
        self.isAuthenticated = true
        self.isAuthenticating = false
        self.statusText = "Authenticated"
    }
}
```

### onAuthenticationFailure(error: String)

Called when authentication fails.

| Parameter | Type     | Description                                 |
| --------- | -------- | ------------------------------------------- |
| `error`   | `String` | Error message describing the failure reason |

```swift
func onAuthenticationFailure(error: String) {
    DispatchQueue.main.async {
        self.isAuthenticated = false
        self.isAuthenticating = false
        self.statusText = "Authentication failed"
        self.lastError = error
    }
}
```

### onLocalizationSuccess(result: LocalizationResult)

Called when localization succeeds. In `LandingView`, this is handled by the AR view.

| Parameter | Type                 | Description                                                                   |
| --------- | -------------------- | ----------------------------------------------------------------------------- |
| `result`  | `LocalizationResult` | Contains map ID, position, rotation, confidence, and optional geo-coordinates |

### onLocalizationFailure(error: String)

Called when localization fails. In `LandingView`, this is handled by the AR view.

| Parameter | Type     | Description                                 |
| --------- | -------- | ------------------------------------------- |
| `error`   | `String` | Error message describing the failure reason |

### onTrackingStateChanged(state: TrackingState)

Called when AR tracking state changes. In `LandingView`, this is handled by the AR view.

| Parameter | Type            | Description                                                 |
| --------- | --------------- | ----------------------------------------------------------- |
| `state`   | `TrackingState` | Current tracking state (`.tracking`, `.paused`, `.stopped`) |

### onObjectTrackingSuccess(objectCode: String, confidence: Float)

Called when an object is successfully detected. In `LandingView`, this is handled by `ARObjectTrackingView`.

| Parameter    | Type     | Description                    |
| ------------ | -------- | ------------------------------ |
| `objectCode` | `String` | Code of the detected object    |
| `confidence` | `Float`  | Detection confidence (0.0–1.0) |

### onObjectTrackingFailure(error: String)

Called when object tracking fails. In `LandingView`, this is handled by `ARObjectTrackingView`.

| Parameter | Type     | Description                                 |
| --------- | -------- | ------------------------------------------- |
| `error`   | `String` | Error message describing the failure reason |

***

## LocalizationResult

| Property         | Type               | Description                                      |
| ---------------- | ------------------ | ------------------------------------------------ |
| `mapId`          | `String`           | The ID of the map where localization succeeded   |
| `mapIds`         | `[String]`         | All map IDs (for mapSets)                        |
| `position`       | `SIMD3<Float>`     | XYZ position coordinates                         |
| `rotation`       | `simd_quatf`       | XYZW quaternion rotation                         |
| `confidence`     | `Float?`           | Confidence score of the localization (0.0 - 1.0) |
| `geoCoordinates` | `GeoCoordinates?`  | Optional geographic coordinates                  |
| `mode`           | `LocalizationMode` | The localization mode used                       |

***

## TrackingState

| Value       | Description                       |
| ----------- | --------------------------------- |
| `.tracking` | AR tracking is working normally   |
| `.paused`   | AR tracking is temporarily paused |
| `.stopped`  | AR tracking has stopped           |

***

## LocalizationMode

| Value          | Description                                           |
| -------------- | ----------------------------------------------------- |
| `.singleFrame` | Single frame capture mode - quick but lower accuracy  |
| `.multiFrame`  | Multi-frame capture mode - slower but higher accuracy |

***

## Usage Example

```swift
import SwiftUI
import MultiSetSDK

struct LandingView: View {
    @StateObject private var sdkDelegate = MultiSetSDKDelegate()
    @State private var navigateToAR = false
    @State private var navigateToObjectTracking = false
    @State private var selectedMode: LocalizationMode = .multiFrame

    var body: some View {
        NavigationStack {
            VStack {
                // Mode selection
                Picker("Mode", selection: $selectedMode) {
                    ForEach(LocalizationMode.allCases) { mode in
                        Text(mode.rawValue).tag(mode)
                    }
                }
                .pickerStyle(SegmentedPickerStyle())

                // Auth button
                Button("Authenticate") {
                    initializeSDK()
                }
                .disabled(sdkDelegate.isAuthenticated)

                // Localize button
                Button("Start Localization") {
                    navigateToAR = true
                }
                .disabled(!sdkDelegate.isAuthenticated)

                // Object Tracking button
                Button("Start Object Tracking") {
                    navigateToObjectTracking = true
                }
                .disabled(!sdkDelegate.isAuthenticated)
            }
            .navigationDestination(isPresented: $navigateToAR) {
                ARLocalizationView(
                    sdkDelegate: sdkDelegate,
                    localizationMode: selectedMode
                )
                .navigationBarBackButtonHidden(true)
            }
            .navigationDestination(isPresented: $navigateToObjectTracking) {
                ARObjectTrackingView(sdkDelegate: sdkDelegate)
                    .navigationBarBackButtonHidden(true)
            }
        }
    }

    private func initializeSDK() {
        var config = SDKConfig.buildConfig()
        config.localizationMode = selectedMode
        MultiSet.shared.initialize(config: config, callback: sdkDelegate)
    }
}
```

***

## Lifecycle

### onAppear

* Checks if credentials are configured
* Auto-initializes SDK if credentials exist and not yet initialized

### Navigation

* Uses `NavigationStack` with `navigationDestination` for programmatic navigation
* Passes `sdkDelegate` and `localizationMode` to `ARLocalizationView`

***

## Related

* [ARLocalizationView](/multiset/native-support/ios-swift-native/sample-views/arlocalizationview.md)
* [ARObjectTrackingView](/multiset/native-support/ios-swift-native/sample-views/arobjecttrackingview.md)
* [MultiSetConfig](/multiset/native-support/ios-swift-native/api-reference/multisetconfig.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://multiset.gitbook.io/multiset/native-support/ios-swift-native/sample-views/landingview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
