iPhone quick switch
Enable seamless app transition between multiple iPhones.
Overview
iPhone quick switch enables your app to receive notifications from the system when someone activates a iPhone as their currently active device for a specific phone number or queries the system about a device’s current state.
There are two ways adopt iPhone quick switching:
Create a CTQuickSwitchManager object, and, optionally, subscribe to the CTQuickSwitchManager.Delegate protocol to receive notification state changes.
Query the a device’s
CTQuickSwitchstate directly.
The following example shows how to create a CTQuickSwitchManager, register and de-register for events, check the quick switch state for a specific phone number, and check the device’s current state.
The following examples show how to create a CTQuickSwitchManager, register and de-register for events, check the quick switch state for a specific phone number, and check the device’s current state using asynchronous calls in Swift.
// Create an instance of the `CTQuickSwitchManager` and set the delegate.
let manager = CTQuickSwitchManager()
manager.delegate = self // Assuming `self` conforms to `CTQuickSwitchManager.Delegate`
// Check the QuickSwitch state of a specific phone number.
let state = try await manager.phoneNumberState(for: "5550")
switch state {
case .active:
// This device is active.
case .passive:
// This device is passive.
case .notEnrolled:
// QuickSwitch is not configured for this number.
case .failed:
fallthrough
@unknown default:
break
}
// Check the overall device QuickSwitch state.
let deviceState = try await manager.deviceState
if deviceState == .passive {
// Device is passive.
}
// Register for quick switch state events.
if let _ = try? await CTQuickSwitchManager.registerForLaunchOnQuickSwitchStateEvents() {
print("Registration successful.")
} else {
print("Registration failed.")
}
// Un-register for quick switch state events.
if let _ = try? await CTQuickSwitchManager.unregisterForLaunchOnQuickSwitchStateEvents() {
print("De-registration successful.")
} else {
print("App wasn't registered for launch on quick switch events.")
}
// Implement the delegate callback to receive state changes.
func quickSwitchManager(_ manager: CTQuickSwitchManager, didChangeToState state: CTQuickSwitchManager.State) {
// Handle the updated state.
}