fix notice
This commit is contained in:
parent
c9dce3e5cd
commit
9708a00106
@ -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([
|
||||
@ -37,11 +39,17 @@ struct dimensionhubApp: App {
|
||||
UserDefaults.standard.set(Utils.defaultUserId(), forKey: "userId")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user