# Troubleshooting

> Canonical URL: https://docs.mountaya.com/en/sdks/swift/troubleshooting/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Fix the Swift SDK errors developers hit first: MapView unavailable, a refused key, a blank map, search refused, webhooks that do not verify and a silent voice.

The problems developers hit first with the Swift SDK, each with its fix.

## `MapView` is unavailable

The package's `Elements` trait is off, or the target is not iOS. Turn the trait on where you depend on the package:

```swift
.package(url: "https://github.com/mountaya/sdk-swift", from: "0.1.0", traits: ["Elements"])
```

In Xcode, turn on **Elements** in the package's traits under **Package Dependencies**. On macOS, tvOS, watchOS or visionOS, hold the map's state with `MapEngine` and draw it yourself.

- The diagnostic names the fix: without the trait it says to depend on the package with `traits: ["Elements"]`; off iOS it says to hold the map's state with `MapEngine`. Every SwiftUI view of `MountayaElements` shares the condition `Elements && os(iOS) && !targetEnvironment(macCatalyst)`.
- The `traits:` argument needs a consumer manifest at tools 6.1 or newer.

## `secret(key:)` is unavailable in an app

A secret key belongs on a server, and an app build cannot name one. Mint session tokens on your server, and give the app a publishable key with a `SessionTokenEngine` ([authentication](https://docs.mountaya.com/en/sdks/swift/authentication.md#rotate)).

- `.secret(key:)`, `Credential(secretKey:…)` and `constructWebhookEvent` are unavailable on iOS, iPadOS, tvOS, watchOS, visionOS and Mac Catalyst. Code shared between an app and a server guards its server part with `#if os(macOS) || os(Linux)`.

## The client throws a configuration error at launch

The key the app read is empty: Info.plist holds `$(MOUNTAYA_PUBLISHABLE_KEY)` unresolved. Check that your target's configuration file includes `Local.xcconfig`, and that the key is set there. Log what the app read:

```swift
import Foundation

let key = Bundle.main.object(forInfoDictionaryKey: "MOUNTAYA_PUBLISHABLE_KEY") as? String
print(key?.isEmpty == false ? "key found" : "no key in Info.plist")
```

- `Mountaya(credential:)` throws `MountayaError.configuration` where a key or token lacks its prefix (`pk_`, `sk_`, `sess_`, `share_`), an empty one included, where a header value is outside printable ASCII, or where a base URL has no scheme. The message names what was refused.
- An xcconfig reads `//` as a comment, so a URL setting is written `https:/$()/example.com/session`.

## The map stays empty

The Tile API refused your key, most often for a missing `tiles` scope. `map.state.isAccessRequired` turns true, and `events()` tells an `.accessRefused` with its status. Add the scope to the key under **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

- `401`: unknown key or expired token. `402`: the organization's agreement does not cover the Tile API. `403`: the key lacks `tiles`, or the app's bundle is not allowed under **Organization → Security**.
- A map with no terrain shown calls `setTerrain()` once it appears (`.task { try? await map.setTerrain() }`).
- `.failure(url:status:cause:)` with a `cause` is a request that never left, for want of a credential the client could read.

## Search or a Data API call answers 401

The Data API takes a publishable key only beside a session token. Give the client a `SessionTokenEngine` over your server's `POST /session` route ([authentication](https://docs.mountaya.com/en/sdks/swift/authentication.md#rotate)).

- The error is `.api` with `kind == .authentication`. A session token that expired is minted again by the engine before it expires; one given as a plain value is not.
- `SearchControl` reads through its map's client, so that client needs the token.

## A write answers 401

A write acts as a member. Mint its session for the `studio-embedded` product and name the member ([act as a member](https://docs.mountaya.com/en/sdks/swift/authentication.md#act-as-member)).

- A token minted for another product, or one minted without `user_id`, is refused `401`. The mint itself is refused `402` without Embedded Studio, and `403` for a key without the `studio-embedded` scope.

## A call answers 402

Your organization's agreement does not cover the call, or its billing needs a payment method. It is fixed in the Mountaya app's billing settings or with Mountaya, never in code: catch `.api` with `kind == .billing` and say so.

- A `402` is always `.billing`, whatever its entry says. The API checks the product before the key's scopes, so enabling a scope does not lift a `402`.

## A webhook delivery never verifies

The body was decoded and encoded again before verification. Pass `constructWebhookEvent` the raw bytes your web framework received, and the endpoint's own secret, `whsk_` included.

- `refusal.reason` says which: `.missingHeader`, `.malformedHeader`, `.signature` (wrong secret or changed body), `.timestamp` (your server's clock is more than the tolerance, 300 seconds, away from the signing time).
- A secret without `whsk_` throws `.configuration`, not a refusal.

## Navigation reads no position

`DeviceLocationSource` never asks for location access. Ask yourself, with a purpose string in Info.plist, and on the simulator pick a location under **Features → Location**:

```swift
import CoreLocation
import MountayaNavigation

@MainActor
func askForLocation(_ access: CLLocationManager, source: DeviceLocationSource) {
  access.requestWhenInUseAuthorization()
  print(source.recheckPermission().authorization)
}
```

- The source reads while the app holds when-in-use or always access at full accuracy. Under reduced accuracy (the reader allowed only an approximate position) `standing.accuracy` is `.reduced` and navigation reads nothing precise enough to follow a route.
- `NSLocationWhenInUseUsageDescription` must be in Info.plist, or the system never shows its prompt.
- A failure reaches the source's `onError` as a `LocationError`: `.providerDisabled` (location services off), `.permissionRevoked`, `.platformFailed`, `.backgroundUndeclared`. A source given no `onError` drops them; a debug build prints them.
- With the screen off, the source reads only where the app declares `location` under `UIBackgroundModes` and is made with `backgroundUpdates: true`.

## Navigation says nothing

The engine was given no voice, or the device has none for the language. Hand it a `SpeechNavigationVoice` with a `fallbackLanguage`, and give it an `onError` to hear a refused audio session.

- `InertNavigationVoice` is the default and says nothing. With the screen off, the voice speaks only where the app declares `audio` under `UIBackgroundModes`.
- No position arrives without location access: `DeviceLocationSource` never asks, so call `requestWhenInUseAuthorization()` yourself and read `standing`.

## The build refuses the platform version

SwiftPM or Xcode names the floor your target falls short of. Raise the target's deployment version to the package's floor:

| Floor | Version |
| --- | --- |
| Swift | 6.2.3 or newer |
| iOS and iPadOS | 17 or newer |
| Mac Catalyst | 17 or newer |
| macOS | 14 or newer |
| tvOS | 17 or newer |
| visionOS | 1 or newer |
| watchOS | 10 or newer |

- The floors are the package's `Package.swift`: `swift-tools-version: 6.2.3`, `.iOS(.v17)`, `.macCatalyst(.v17)`, `.macOS(.v14)`, `.tvOS(.v17)`, `.visionOS(.v1)`, `.watchOS(.v10)`. Each platform's is the release Observation arrived in. Linux needs only that Swift.
- A consumer manifest at a tools version below 6.1 cannot turn the `Elements` trait on.
- An Xcode project raises its floor under the target's **General → Minimum Deployments**.

## Next steps

- [Errors and retries](https://docs.mountaya.com/en/sdks/swift/errors.md): Every error case and code.
- [Install and set up](https://docs.mountaya.com/en/sdks/swift/install.md): The trait, the key and the imports.
