> For the complete documentation index, see [llms.txt](https://docs.multiset.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetcallback.md).

# MultiSetCallback

The protocol your app implements for SDK events: authentication, localization, tracking state, false positives, alignment changes and mesh loading.

## Overview

`MultiSetCallback` is the protocol your app implements to receive SDK events: authentication, localization, object tracking, and mesh loading. The instance is passed to `MultiSet.shared.initialize(config:callback:)` and is held weakly by the SDK.

```swift
class MultiSetSDKDelegate: MultiSetCallback {
    func onSDKReady() { }
    func onAuthenticationSuccess() { }
    func onAuthenticationFailure(error: String) { }
    func onLocalizationSuccess(result: LocalizationResult) { }
    func onLocalizationFailure(error: String) { }
    func onTrackingStateChanged(state: TrackingState) { }
}
```

Only the six methods above are required. Every other method has a default no-op implementation, so existing integrations keep compiling when new callbacks are added.

`MultiSetCallback` is isolated to the main actor, and every method is called on the main thread: update UI and `@Published` state directly. A class that adopts it in its declaration is inferred `@MainActor`, so create it on the main thread.

***

## Required Methods

### onSDKReady()

Called synchronously from `initialize(config:callback:)`, before authentication starts.

This is not an authentication signal. Wait for `onAuthenticationSuccess()` before calling `localize()`. Attaching an `ARSession` here is safe, because the SDK applies it once authenticated.

### onAuthenticationSuccess()

Authentication with the MultiSet servers succeeded. The SDK is ready to localize.

### onAuthenticationFailure(error: String)

Authentication failed.

| Parameter | Type     | Description                |
| --------- | -------- | -------------------------- |
| `error`   | `String` | Description of the failure |

### onLocalizationSuccess(result: LocalizationResult)

A pose was returned and accepted. The gizmo has moved and, if `meshVisualization` is enabled, the mesh is loading.

| Parameter | Type                 | Description                                                                                                        |
| --------- | -------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `result`  | `LocalizationResult` | See [LocalizationResult](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/localizationresult.md) |

### onLocalizationFailure(error: String)

The localization request failed, or no pose was found.

| Parameter | Type     | Description                |
| --------- | -------- | -------------------------- |
| `error`   | `String` | Description of the failure |

When `firstLocalizationUntilSuccess` is enabled, a failed first fix is retried silently up to 5 times before it reaches this callback. Runs that recover from a tracking break never reach it.

### onTrackingStateChanged(state: TrackingState)

ARKit tracking state changed. Delivered synchronously; the first call is ARKit's first real state change.

| Parameter | Type            | Description                          |
| --------- | --------------- | ------------------------------------ |
| `state`   | `TrackingState` | `.tracking`, `.paused` or `.stopped` |

***

## Optional Methods

Each of these has a default empty implementation.

### onLocalizationFalsePositive(info: FalsePositiveInfo)

The server returned a pose, but it contradicts the device's own AR trajectory, so the SDK discarded it. This fires **instead of** `onLocalizationSuccess`, and only when [`poseConsistencyCheck`](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetconfig.md#pose-consistency-settings) is enabled.

The request itself succeeded. The answer was wrong, most likely because the query image matched a visually similar part of the space. The AR scene is left untouched: the gizmo and mesh keep the last accepted pose.

| Parameter | Type                | Description                                  |
| --------- | ------------------- | -------------------------------------------- |
| `info`    | `FalsePositiveInfo` | Details of the discarded response, see below |

```swift
func onLocalizationFalsePositive(info: FalsePositiveInfo) {
    print("Discarded: \(info.summary)")

    switch info.rejection {
    case .falsePositive: showHint("Localize again from somewhere more distinctive")
    case .reestablishing: break                    // re-anchoring after an interruption
    case .suspectedAliasing: showResetPrompt()     // localizing again from here will not help
    @unknown default: break
    }
}
```

A retry from the same spot tends to produce the same wrong match, so prompt the user to move to a more distinctive viewpoint. When the first fix itself was wrong, every correct response afterwards is the one rejected: offer `MultiSet.shared.resetSession()` from this UI so the user can start over.

### onLocalizationCorrected(from: AnchorPose, to: AnchorPose, trust: AnchorTrust)

Agreeing fixes from separated viewpoints out-voted the anchor, and the map moved. Fires alongside `onLocalizationSuccess`. Re-place any content you anchored in world space yourself.

### onAnchorTrustChanged(\_ trust: AnchorTrust)

The pose consistency anchor's standing changed: `.provisional`, `.corroborated` or `.trusted`. `MultiSet.shared.anchorTrust` holds the same value.

### onRecoveryPhaseChanged(\_ phase: RecoveryPhase, needsRealignment: Bool)

The recovery after a tracking break moved on: `.none`, `.waitingForTracking` or `.realigning`. Hide content placed in the map frame while `needsRealignment` is `true`. See [Recovery after a tracking break](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/lifecycle-and-runtimes.md#recovery-after-a-tracking-break).

### onAlignmentChanged(map: MapAlignment?, geo: GeoAlignment?)

Requires iOS SDK 2.4.0 or later.

`MultiSet.shared.mapAlignment` or `geoAlignment` changed, or either availability did. It fires once per change: on every accepted fix, and with `nil` when the alignment is cleared, for example after a tracking break or `resetSession()`. On a fix it fires just before `onLocalizationSuccess`, after the scene's map anchor has moved.

| Parameter | Type            | Description                                                         |
| --------- | --------------- | ------------------------------------------------------------------- |
| `map`     | `MapAlignment?` | Where the map sits in the AR session, or `nil`                      |
| `geo`     | `GeoAlignment?` | Where the AR session sits on Earth, or `nil` when it is unavailable |

Use it to place geo-located content again after each fix, and to hide it when `geo` is `nil`. Apps that render every frame can read the same values from `MultiSet.shared` instead. See [Polling API](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/polling-api.md).

```swift
func onAlignmentChanged(map: MapAlignment?, geo: GeoAlignment?) {
    guard let geo else {
        marker.isEnabled = false
        return
    }
    let pose = geo.sessionPose(of: markerCoordinates, facingDegrees: 90)
    marker.setPosition(pose.position, relativeTo: nil)
    marker.setOrientation(pose.rotation, relativeTo: nil)
    marker.isEnabled = true
}
```

### onLocalizationStageChanged(\_ stage: LocalizationStage, isBackground: Bool)

A localization run moved between capturing, uploading, waiting on the server and idle. `isBackground` is `true` for runs that should not cover the scene. See [Showing a Run's Progress](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/lifecycle-and-runtimes.md#showing-a-runs-progress).

### onObjectTrackingStageChanged(\_ stage: LocalizationStage, isBackground: Bool)

The object tracking counterpart of `onLocalizationStageChanged`.

### onMeshLoaded(mapCode: String)

A map mesh finished downloading and rendering. It fires after every accepted fix, whether or not a mesh was drawn.

| Parameter | Type     | Description                           |
| --------- | -------- | ------------------------------------- |
| `mapCode` | `String` | Code of the map whose mesh was loaded |

### onMeshLoadError(error: String)

Mesh download or rendering failed. Localization itself is unaffected.

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

A tracked object was located and its outline mesh placed.

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

### onObjectTrackingFailure(error: String)

Object tracking failed or no object was matched.

### onObjectMeshLoaded(objectCode: String)

An object mesh was loaded and rendered with the outline shader. With no mesh renderer attached, meshes are not downloaded and this does not fire.

***

## FalsePositiveInfo

Details of a localization response that the pose consistency check discarded.

| Property                                                   | Type                  | Description                                                                               |
| ---------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------- |
| `jumpMeters`                                               | `Float`               | How far the discarded response placed the map from the anchor                             |
| `yawDeltaDeg`                                              | `Float`               | How far its heading was from the anchor's, in degrees                                     |
| `thresholdMeters`                                          | `Float`               | The distance limit in force: exactly `poseConsistencyThreshold`                           |
| `thresholdDegrees`                                         | `Float`               | The heading limit in force: exactly `poseConsistencyYawThreshold`                         |
| `disagreement`                                             | `GateDisagreement?`   | `.distance`, `.heading` or `.both`: which limit was broken                                |
| `cause`                                                    | `FalsePositiveCause?` | `.insufficientViewpoints`, `.anchorHeldVote` or `.inlierMargin`: why the contest was lost |
| `challengerSupport`, `requiredSupport`, `incumbentSupport` | `Int`                 | Viewpoints behind the response, needed to move the anchor, and behind the anchor          |
| `consecutiveCount`                                         | `Int`                 | Consecutive rejections since the last accepted fix. `1` on the first one                  |
| `trust`                                                    | `AnchorTrust`         | Standing of the anchor that was kept                                                      |
| `rejection`                                                | `GateRejection`       | What to tell the user, see below                                                          |
| `mapCodes`                                                 | `[String]`            | Map codes the server reported for the discarded response                                  |
| `confidence`                                               | `Float?`              | Server confidence of the discarded response, when reported                                |
| `reason`                                                   | `String`              | Short machine-readable explanation, for logs                                              |
| `summary`                                                  | `String`              | One-line description of all of the above, ready to log                                    |

Read `disagreement` and `cause` before quoting any of those numbers at a user. A response can sit well inside `thresholdMeters` and still be refused on heading, and on `.anchorHeldVote` the response had every viewpoint it needed and lost on a tie.

| `rejection`          | Meaning                                                                   | What to do                                                     |
| -------------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `.falsePositive`     | The response contradicts an anchor that AR tracking still vouches for     | Ask the user to localize again from somewhere more distinctive |
| `.reestablishing`    | AR tracking was interrupted, and the SDK is collecting a fix to re-anchor | Nothing; not worth showing                                     |
| `.suspectedAliasing` | The server keeps matching a structurally identical part of the space      | Localizing again will not help. Offer a reset                  |

A high `confidence` on a discarded response is normal and is the point of the check. The server was sure about a match that the device's own motion rules out.

***

## Related

* [MultiSetConfig](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetconfig.md)
* [LocalizationResult](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/localizationresult.md)
* [Polling API](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/polling-api.md)
* [Lifecycle and AR Runtimes](https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/lifecycle-and-runtimes.md)
* [LandingView](https://docs.multiset.ai/native-sdk/ios-swift-native/sample-views/landingview.md)
* [ARLocalizationView](https://docs.multiset.ai/native-sdk/ios-swift-native/sample-views/arlocalizationview.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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.multiset.ai/native-sdk/ios-swift-native/api-reference/multisetcallback.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
