收到本地通知后如何自动打开(不单击通知)视图控制器

问题描述 投票:0回答: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()
 //   }

}

我想在收到本地通知时自动打开控制器/(Ios App),而无需单击通知,是否可以..? func applicationDidEnterBackground(_ application:...

swift swift4 swift4.2 swift4.1 swift4.1.5
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.