【发布时间】:2021-01-29 20:59:57
【问题描述】:
我正在使用 SwiftUI 2.0,并且正在尝试实现 firebase 推送通知。 在新的 SwiftUI 应用结构中,没有 AppDelegate 和 SceneDelegate,所以我创建了 AppDelegate 类。我设法接收通知,但我无法在通知点击时转到特定视图。 这是我的代码:
@main
struct swiftUiApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
和 AppDelegate 扩展:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let orders = Orders()
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
if(userInfo["gcm.notification.type"] != nil){
if(userInfo["gcm.notification.type"] as! String == "order"){
//here I need to navigate to OrderView
}
}
}
【问题讨论】:
标签: ios push-notification swiftui ios14 firebase-notifications