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.
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:- Go to File → Add Package Dependencies…
- Enter:
https://github.com/stytchauth/stytch-ios-sdk - Select version 1.0.0 or later
- Add the product that matches your project type:
StytchConsumerSDK— Consumer (B2C) appsStytchB2BSDK— B2B apps (organizations/members)
Package.swift:
-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; callingcreateStytchConsumer again returns the same instance.
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 anauthenticationStateFlow — an async sequence that emits whenever authentication state changes. Use for await to observe it:
stytch.authenticationStateFlow.value.
4. Auth Methods
All SDK methods areasync throws. Call them from a Task or an async context and handle errors with do/catch. Errors are thrown as StytchError.
SMS OTP Example
5. Handle Deeplinks
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 likemyapp://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: