Skip to main content
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.
For a full walk-through of how to get up and running with a sign-up and login flow using Stytch, check out our Quickstart Guide.
1

Add the package

Add the Stytch iOS package via Swift Package Manager. In Xcode, go to File → Add Package Dependencies and enter the repository URL:
https://github.com/stytchauth/stytch-ios-sdk
Select the StytchB2BSDK product and add it to your target.
2

Configure URL scheme

To handle magic links, register a custom URL scheme in your app’s Info.plist:
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>your-app-scheme</string>
        </array>
    </dict>
</array>
Then pass this scheme as the loginRedirectUrl and signupRedirectUrl when starting magic link flows, and handle the incoming URL in your AppDelegate or SceneDelegate by calling stytch.authenticate(url:).
3

Create the Stytch client

Initialize the Stytch client with your Project’s public_token from the Project Overview of the Stytch Dashboard.
import StytchB2BSDK

let stytch = createStytchB2B(configuration: .init(publicToken: "public-token-test-1234"))
The client is a singleton — subsequent calls to createStytchB2B return the same instance.
4

Observe authentication state

Subscribe to authenticationStateFlow to react to sign-in and sign-out events:
Task {
    for await state in stytch.authenticationStateFlow {
        // state is B2BAuthenticationState.Authenticated, Unauthenticated, or Loading
    }
}