fix notice
This commit is contained in:
parent
c9dce3e5cd
commit
9708a00106
@ -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()
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user