fix notice

This commit is contained in:
anlicheng 2025-04-07 11:52:37 +08:00
parent c9dce3e5cd
commit 9708a00106

View File

@ -7,10 +7,12 @@
import SwiftUI import SwiftUI
import SwiftData import SwiftData
import Observation
@main @main
struct dimensionhubApp: App { struct dimensionhubApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@State var appNav = AppNavigation.shared
var sharedModelContainer: ModelContainer = { var sharedModelContainer: ModelContainer = {
let schema = Schema([ let schema = Schema([
@ -37,11 +39,17 @@ struct dimensionhubApp: App {
UserDefaults.standard.set(Utils.defaultUserId(), forKey: "userId") UserDefaults.standard.set(Utils.defaultUserId(), forKey: "userId")
} }
} }
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
NavigationStack { NavigationStack(path: $appNav.path) {
IndexView() IndexView()
.navigationDestination(for: AppNavigation.Destination.self) { dest in
switch dest {
case .detail(id: let id):
DetailView(id: id)
}
}
} }
.navigationViewStyle(.stack) .navigationViewStyle(.stack)
.tint(.black) .tint(.black)
@ -130,9 +138,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
willPresent notification: UNNotification, willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo //let userInfo = notification.request.content.userInfo
// //
handleRemoteNotification(userInfo: userInfo) //handleRemoteNotification(userInfo: userInfo)
// //
completionHandler([.banner, .sound]) completionHandler([.banner, .sound])
@ -145,9 +153,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let userInfo = response.notification.request.content.userInfo let userInfo = response.notification.request.content.userInfo
//
handleRemoteNotification(userInfo: userInfo) handleRemoteNotification(userInfo: userInfo)
// //
if let deepLink = userInfo["deepLink"] as? String { if let deepLink = userInfo["deepLink"] as? String {
handleDeepLink(deepLink) handleDeepLink(deepLink)
@ -159,18 +165,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
// MARK: // MARK:
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) { private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
print("收到远程通知: \(userInfo)") if let customData = userInfo["custom_data"] as? [String: AnyObject],
let dramaId = customData["drama_id"] as? Int {
// AppNavigation.shared.path.append(AppNavigation.Destination.detail(id: dramaId))
if let aps = userInfo["aps"] as? [String: AnyObject] {
if let alert = aps["alert"] as? String {
print("通知消息: \(alert)")
}
//
if let customData = userInfo["customData"] as? [String: AnyObject] {
print("自定义数据: \(customData)")
}
} }
} }
@ -180,3 +177,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
} }
} }
@Observable
final class AppNavigation {
static var shared = AppNavigation()
enum Destination: Hashable {
case detail(id: Int)
}
private init() {
}
var path = NavigationPath()
}