-1

我想在收到本地通知时,自动查看控制器/(Ios App)打开而不点击通知,是否可能..?

func applicationDidEnterBackground(_ application: UIApplication) {

  print("EnterBackground.")
    //Crete a local notification
    let notification = UILocalNotification()
    notification.alertBody = "This is a fake notification"
    notification.fireDate  = NSDate(timeIntervalSinceNow: 2) as Date
    UIApplication.shared.scheduleLocalNotification(notification)

    let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "ScreenLockedViewController") as UIViewController
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = initialViewControlleripad
    self.window?.makeKeyAndVisible()

 //   NotificationCenter.default.post(name: NSNotification.Name(rawValue: "launchSecondView"), object: nil)
 //   if let viewController = window?.rootViewController as? ViewController {
 //       viewController.viewDidLoad()
 //   }

}
4

1 回答 1

0

在 iOS 13.2 及更早版本中,您无法实现它,用户必须点击通知才能打开应用程序。

于 2019-12-06T21:06:21.870 回答