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 SwiftData
import Observation
@main
struct dimensionhubApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@State var appNav = AppNavigation.shared
var sharedModelContainer: ModelContainer = {
let schema = Schema([
@ -40,8 +42,14 @@ struct dimensionhubApp: App {
var body: some Scene {
WindowGroup {
NavigationStack {
NavigationStack(path: $appNav.path) {
IndexView()
.navigationDestination(for: AppNavigation.Destination.self) { dest in
switch dest {
case .detail(id: let id):
DetailView(id: id)
}
}
}
.navigationViewStyle(.stack)
.tint(.black)
@ -130,9 +138,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
willPresent notification: UNNotification,
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])
@ -145,9 +153,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let userInfo = response.notification.request.content.userInfo
//
handleRemoteNotification(userInfo: userInfo)
//
if let deepLink = userInfo["deepLink"] as? String {
handleDeepLink(deepLink)
@ -159,18 +165,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
// MARK:
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
print("收到远程通知: \(userInfo)")
//
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)")
}
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))
}
}
@ -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()
}