// // PhoneSync.swift // Keging // // 워치 연동 (iOS 측) — 워치에서 완주한 기록을 받아 병합하고, 연결 상태를 알린다. // 세팅은 기기별 독립(2026-09-03, 7차 — 기기마다 진동 질감이 달라 각자 최적화)이라 // 더 이상 push/응답하지 않는다. // import WatchConnectivity final class PhoneSync: NSObject, WCSessionDelegate { static let shared = PhoneSync() private override init() { super.init() } func activate() { guard WCSession.isSupported() else { return } let session = WCSession.default session.delegate = self session.activate() } private nonisolated func refreshLinkStatus() { Task { @MainActor in WatchLinkStatus.shared.refresh() } } // MARK: WCSessionDelegate nonisolated func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { refreshLinkStatus() } nonisolated func sessionDidBecomeInactive(_ session: WCSession) {} nonisolated func sessionDidDeactivate(_ session: WCSession) { session.activate() } nonisolated func sessionReachabilityDidChange(_ session: WCSession) { refreshLinkStatus() } /// 페어링·워치 앱 설치 여부 변화 nonisolated func sessionWatchStateDidChange(_ session: WCSession) { refreshLinkStatus() } nonisolated func session(_ session: WCSession, didReceiveUserInfo userInfo: [String: Any] = [:]) { guard let data = userInfo["record"] as? Data, let record = try? JSONDecoder().decode(SessionRecord.self, from: data) else { return } Task { @MainActor in RecordStore.shared.append(record) } } }