-1

I want when local notification received, automatically view controller / (Ios App) is open whithout click on notification,, is possible or not..?

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()
 //   }

}
Jake
  • 11,465
  • 8
  • 40
  • 70

1 Answers1

0

In iOS 13.2 and older you cannot achieve it, user must tap on notification to open the app.

Roman Podymov
  • 3,800
  • 3
  • 32
  • 54