gpt4 book ai didi

当应用程序被杀死时 ios 通知 firebase 重定向特定 View

转载 作者:行者123 更新时间:2023-11-29 00:01:22 27 4
gpt4 key购买 nike

早上好,开发一个应用程序,我使用 firebase 接收通知,如果我发送通知并且应用程序被终止,我会遇到问题,我打开应用程序的第一页,而不是我想打开一个特定的 View ,这是我的代码

func application (_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

FirebaseApp.configure ()


// locally save data for settings

let launchedBefore = UserDefaults.standard.bool (forKey: "launchedBefore")
if launchedBefore {
print ("Not first launch.")
} else {
print ("First launch, setting UserDefault.")
UserDefaults.standard.set (true, forKey: "isNotify")
UserDefaults.standard.set (false, forKey: "isZoom")
UserDefaults.standard.set (true, forKey: "isCookie")
if UserDefaults.standard.bool (forKey: "isNotify") {
registerNotification ()
}
UserDefaults.standard.set (true, forKey: "launchedBefore")
}
NotificationCenter.default.addObserver (self, selector: #selector (registerNotification), name: NSNotification.Name (rawValue: "isNotify"), object: nil)
return true
}

func registerNotification () {
if #available (iOS 10, *) {
UNUserNotificationCenter.current (). RequestAuthorization (options: [. Badge, .alert, .sound]) {(granted, error) in}
UIApplication.shared.registerForRemoteNotifications ()
}
// iOS 9 support
else {
UIApplication.shared.registerUserNotificationSettings (UIUserNotificationSettings (types: [.badge, .sound, .alert], categories: nil))
UIApplication.shared.registerForRemoteNotifications ()
}
}

最佳答案

在 didFinishLaunchingWithOptions 方法中,像这样阅读通知:

        let notification = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary
if notification != nil {
// Read the notification payload and open related page
}

关于当应用程序被杀死时 ios 通知 firebase 重定向特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49422998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com