Skip to main content

iOS Quickstart

This guide is for our new Kotlin Multiplatform SDK which is in Public beta. If you are instead looking for the stable version, please see stytch-ios and the usage docs here.
This guide walks you through adding Stytch authentication to an iOS app using StytchConsumerSDK or StytchB2BSDK. Both are distributed as a Swift Package from stytchauth/stytch-ios-sdk and require iOS 15.0+.

1. Install the SDK

In Xcode:
  1. Go to File → Add Package Dependencies…
  2. Enter: https://github.com/stytchauth/stytch-ios-sdk
  3. Select version 1.0.0 or later
  4. Add the product that matches your project type:
    • StytchConsumerSDK — Consumer (B2C) apps
    • StytchB2BSDK — B2B apps (organizations/members)
In Package.swift:
Required linker flag: In your target’s Build Settings, add -ObjC to Other Linker Flags.

2. Initialize the Client

Create the client once — at app startup or at the entry point of your auth flow. The client is a singleton; calling createStytchConsumer again returns the same instance.
For B2B apps, import StytchB2BSDK and use createStytchB2B(configuration:) instead. Your public token is in the Stytch Dashboard. Make sure you’ve also enabled the auth methods you want to use under SDK Configuration.

3. Observe Authentication State

The SDK exposes an authenticationStateFlow — an async sequence that emits whenever authentication state changes. Use for await to observe it:
To read the current state synchronously (e.g., during a navigation check), use stytch.authenticationStateFlow.value.

4. Auth Methods

All SDK methods are async throws. Call them from a Task or an async context and handle errors with do/catch. Errors are thrown as StytchError.

SMS OTP Example


Magic links and password reset emails redirect back to your app via a URL scheme. 1. Register a redirect URL in the Stytch Dashboard. Use a scheme like myapp://auth. 2. Add a URL scheme to your target in Xcode: go to your target’s Info tab, expand URL Types, click +, and enter your scheme (e.g., myapp) in the URL Schemes field. 3. Receive the URL in SwiftUI or UIKit:
4. Authenticate the deeplink:

6. Session Management

Sessions are automatically persisted across app launches and validated on startup.