如果应用程式处于未使用状态,请处理通知通知

时间:2019-12-06 07:15:45

标签: ios swift apple-push-notifications push

我正在使用Firebase推送通知,当应用程序处于后台和前台状态时,一切运行正常。但是,当应用程序处于终止状态时,请点击通知进入首页。我已经使用了所有可能的方式-通过使用启动选项检查

['A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'A', 'A', 'A']

我不知道我在想什么。请帮忙。

1 个答案:

答案 0 :(得分:0)

   In your appdelegate add this extension.

   extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse, 
                            withCompletionHandler
                            completionHandler: @escaping () -> Void) {
    if UserDefaults.standard.bool(forKey: "login_session") {
        let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", 
        bundle: nil)
        let initialViewControlleripad : UIViewController = 
         mainStoryboardIpad.instantiateViewController(withIdentifier: "Notifs_Main") as UIViewController
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = initialViewControlleripad
        self.window?.makeKeyAndVisible()
    } else {
        UserDefaults.standard.set(false, forKey: "isLoggedin")
        print("failed")
    }
    return completionHandler()
    }
   func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent
    notification: UNNotification, withCompletionHandler completionHandler:
    @escaping (UNNotificationPresentationOptions) -> Void) {
    return completionHandler(UNNotificationPresentationOptions.alert)
   }
 }