WatchNotificationRouter.swift
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// WatchNotificationRouter.swift
// Runner Watch App
//
// Created by 权海 on 2026/6/17.
//
import Foundation
import Combine
final class WatchNotificationRouter: ObservableObject {
static let shared = WatchNotificationRouter()
@Published var pendingNotification: WatchNotificationPayload?
private init() {}
func handle(userInfo: [AnyHashable: Any]) {
let payload = WatchNotificationPayload(userInfo: userInfo)
DispatchQueue.main.async {
self.pendingNotification = payload
}
}
func consumeCachedPayloadIfNeeded() {
// pendingNotification = WatchNotificationPayload(
// id: id,
// type: type
// )
}
}
struct WatchNotificationPayload {
let id: String?
let type: String?
init(userInfo: [AnyHashable: Any]) {
self.id = userInfo["id"] as? String
self.type = userInfo["type"] as? String
}
init(id: String?, type: String?) {
self.id = id
self.type = type
}
}