Fix watch fuel icons and snapshot sync
This commit is contained in:
@@ -9,6 +9,7 @@ final class WatchSyncManager: NSObject, WCSessionDelegate {
|
||||
static let shared = WatchSyncManager()
|
||||
|
||||
private let suiteName = "group.com.apt.fuelboard"
|
||||
private let snapshotRequestKey = "fuelboard.snapshotRequest"
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
@@ -36,6 +37,18 @@ final class WatchSyncManager: NSObject, WCSessionDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func requestSnapshot() {
|
||||
guard WCSession.isSupported() else { return }
|
||||
let payload = [snapshotRequestKey: String(Date().timeIntervalSince1970)]
|
||||
let session = WCSession.default
|
||||
|
||||
if session.isReachable {
|
||||
session.sendMessage(payload, replyHandler: nil, errorHandler: nil)
|
||||
} else {
|
||||
session.transferUserInfo(payload)
|
||||
}
|
||||
}
|
||||
|
||||
private func sharedDefaults() -> UserDefaults? {
|
||||
UserDefaults(suiteName: suiteName)
|
||||
}
|
||||
@@ -74,6 +87,10 @@ final class WatchSyncManager: NSObject, WCSessionDelegate {
|
||||
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: (any Error)?) {
|
||||
if let error {
|
||||
print("WATCH-SYNC activation failed: \(error.localizedDescription)")
|
||||
return
|
||||
}
|
||||
if activationState == .activated {
|
||||
requestSnapshot()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user