如何在收到本地通知时自动打开(无需单击通知)视图控制器



我希望当收到本地通知时,自动查看控制器/(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()
//   }
}

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

相关内容

  • 没有找到相关文章

最新更新