Stytch provides mobile SDKs that make it easy to integrate authentication into your app. As the only provider with a full API suite, Stytch lets you build custom end to end flows. You can choose between two options: Stytch for a fully customizable headless API integration, or StytchUI for prebuilt configurable views that speeds up implementation.
- To begin, sign up and create a new project in the Stytch dashboard.
- When creating a project, you will choose between Consumer Authentication and B2B SaaS Authentication.
- For most iOS apps, you will likely use Consumer Authentication. Learn more in the docs.
- After your project is set up, configure the SDK settings by adding your app's bundle ID under Authorized applications and enabling the Auth methods you want to support.
The Stytch iOS SDK is distributed through the Swift Package Manager. To add the Stytch SDK to your Xcode project, follow these steps.
- Open Xcode
- File > Add Package Dependencies
- Enter https://github.com/stytchauth/stytch-ios in the top right
- Choose Package Requirements and click "Add Package"
- In your Build Settings, under
Other Linker Flags, add-ObjC import StytchCoreorimport StytchUIin your code
https://github.com/stytchauth/stytch-ios
We recommend that you use "Up To Next Major Version" and never point to main or any other branch directly. Knowing what version of the SDK you are using will make it easier for us to support you!
Stytch provides two ways to add authentication to your iOS app:
- π οΈ Stytch: A headless API integration that gives you complete control over the authentication experience.
- π± StytchUI: A reusable UI layer built on top of Stytch. It provides a configurable user flow that you can launch from SwiftUI or UIKit to handle authentication quickly without building every screen yourself.
βΉοΈ When using StytchUI, you can still use the full underlying client for both consumer and B2B integrations. This is useful for π€ observing changes in the user or member, π managing the session, and π§© calling other headless methods relevant to your integration.
| Option | Consumer | B2B |
|---|---|---|
| π οΈ Stytch | StytchClient |
StytchB2BClient |
| π± StytchUI | StytchUIClient |
StytchB2BUIClient |
Below are examples of authenticating with SMS OTP using both the Prebuilt UI and Headless methods. π We recommend starting with StytchUI to speed up integration.
import Combine
import StytchCore
import StytchUI
import SwiftUI
struct ContentView: View {
@StateObject var viewModel = ContentViewModel()
var body: some View {
NavigationView {
VStack(spacing: 20) {
Button("Log In With Stytch!") {
viewModel.shouldShowB2CUI = true
}.font(.title).bold()
}
.authenticationSheet(configuration: viewModel.configuration, isPresented: $viewModel.shouldShowB2CUI)
}
}
}
class ContentViewModel: ObservableObject {
@Published var shouldShowB2CUI: Bool = false
private var cancellables = Set<AnyCancellable>()
let configuration = StytchUIClient.Configuration.init(
stytchClientConfiguration: .init(publicToken: "public-token-test-a9c3f1e2-b7d8-4g5h-9i2j-3k4l5m6n7o8p"),
products: [.otp],
otpOptions: .init(methods: [.sms])
)
init() {
StytchUIClient.configure(configuration: configuration)
StytchUIClient.dismissUI
.receive(on: DispatchQueue.main)
.sink { [weak self] in
self?.shouldShowB2CUI = false
}
.store(in: &cancellables)
}
}Here is a more detailed example of using StytchUI.
import StytchCore
let stytchClientConfiguration = StytchClientConfiguration(
publicToken: "public-token-test-a9c3f1e2-b7d8-4g5h-9i2j-3k4l5m6n7o8p",
defaultSessionDuration: 5
)
StytchClient.configure(configuration: stytchClientConfiguration)import StytchCore
public class OTPAuthenticationManager {
var methodId: String = ""
// Send a OTP (one time passcode) via SMS
func sendOTP() {
Task {
do {
let parameters = StytchClient.OTP.Parameters(deliveryMethod: .sms(phoneNumber: "+12125551234"))
let response = try await StytchClient.otps.send(parameters: parameters)
// save the methodId for the subsequent authenticate call
self.methodId = response.methodId
} catch {
print(error.errorInfo)
}
}
}
// Authenticate a user using the OTP sent via SMS
func authenticateOTP(code: String) {
Task {
do {
let parameters = StytchClient.OTP.AuthenticateParameters(code: code, methodId: methodId)
let response = try await StytchClient.otps.authenticate(parameters: parameters)
print(response.user)
} catch {
print(error.errorInfo)
}
}
}
}Authentication methods in the iOS SDK are namespaced by type. For example, StytchClient includes a type called OTP and a static instance called otps. The same pattern applies to other authentication methods, making it easy to discover and use the available functionality in a consistent way.
StytchCore is written using async/await π¦
but we use Sourcery π§ͺ to generate versions of the API that can be used with Combine π or called with a completion handler.
If you look in the generated directory π you will see the APIs in the files ending in +AsyncVariants that hold the generated concurrency variants.
Explore examples for some of the most common use cases in the SDK:
- Deeplinks
- Email Magic Links
- OAuth
- Passwords
- Sessions
- Stytch UI (Consumer)
- Stytch UI (B2B)
- Localization in the Prebuilt UI
In addition to installing the Swift package, it is highly recommended to clone this repo and explore the sample apps, which provide context and example code to help expedite your integration. More details and Instructions can be found here!
Nidal π¨βπ» is our Stytch iOS lead π and is available to answer any questions about the Stytch iOS SDK π±. He can also help you get started quickly π.
You can book time with him here π .
Join the discussion, ask questions, and suggest new features in our βSlack community!
Check out the Stytch Forum or email us at [email protected].
Full reference documentation is available for StytchCore and StytchUI.
The Stytch iOS SDK is released under the MIT license. See LICENSE for details.


