Watch Connectivity
Use Watch Connectivity to keep an iOS app and its companion watchOS app signed in as the same user. When a user signs in or out on either device, the other device follows.
Confirm a companion watch app
Watch Connectivity only works when your watchOS target is a companion to the iOS app. Make sure your iOS app target is paired with a watchOS target in Xcode. For Apple’s guidance on setting up a companion watch app, see Setting up a watchOS project.
Configure Clerk in both apps
Use the same in both apps and enable watch sync in Clerk.Options:
import ClerkKit
import SwiftUI
@main
struct WatchConnectivityExampleApp: App {
init() {
// Configure Clerk with Watch Connectivity sync enabled
let options = Clerk.Options(
watchConnectivityEnabled: true
)
Clerk.configure(
publishableKey: "YOUR_PUBLISHABLE_KEY",
options: options
)
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(Clerk.shared)
}
}
}import ClerkKit
import SwiftUI
@main
struct WatchConnectivityExampleWatchApp: App {
init() {
// Configure Clerk with Watch Connectivity sync enabled
let options = Clerk.Options(
watchConnectivityEnabled: true
)
Clerk.configure(
publishableKey: "YOUR_PUBLISHABLE_KEY",
options: options
)
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(Clerk.shared)
}
}
}Simulator setup (optional)
For simulator testing, make sure your iPhone simulator is paired with a watchOS simulator in Xcode > Window > Devices and Simulators.
Install and run
- Build and run the iOS app first (this installs the companion watch app).
- Then run the watchOS app.
- Sign in on either device to verify the session syncs.
Feedback
Last updated on