36 lines
908 B
Swift
36 lines
908 B
Swift
import Foundation
|
|
import WatchConnectivity
|
|
|
|
@MainActor
|
|
final class WatchConnectivityService: NSObject, WCSessionDelegate {
|
|
static let shared = WatchConnectivityService()
|
|
|
|
private override init() {
|
|
super.init()
|
|
activateIfSupported()
|
|
}
|
|
|
|
private func activateIfSupported() {
|
|
guard WCSession.isSupported() else { return }
|
|
let session = WCSession.default
|
|
session.delegate = self
|
|
session.activate()
|
|
}
|
|
|
|
func session(
|
|
_ session: WCSession,
|
|
activationDidCompleteWith activationState: WCSessionActivationState,
|
|
error: Error?
|
|
) {
|
|
// Intentionally empty: activation state is handled by WCSession.
|
|
}
|
|
|
|
func sessionDidBecomeInactive(_ session: WCSession) {
|
|
// No-op; required for iOS WCSessionDelegate.
|
|
}
|
|
|
|
func sessionDidDeactivate(_ session: WCSession) {
|
|
session.activate()
|
|
}
|
|
}
|