1

I have been attempting to get local notifications going within my code and have been having a problem with it showing up as an alert and in the local Notification Center. I've tried different codes from online and even tried implementing the example code Apple provides in the manual. Still, no notification drops down on the screen but if I implement a badge count, that shows. Here's what I put in the App Delegate:

  func application(_ application: UIApplication,  didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {granted, Error in})

    UNUserNotificationCenter.current().delegate = self

    return true
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler(.alert)
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    //
}

And Here's what's in my ViewController:

 @IBAction func addReminder(sender: UIButton) {
    taskMgr.addTask(name: textField.text!)
    //self.animateOut()
    let content = UNMutableNotificationContent()

    content.title = NSString.localizedUserNotificationString(forKey: "The alert was successful", arguments: nil)

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)

    let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

}

If everything is correct, could there be something else I'm missing with the simulator? I have already made sure that the notifications for the app is turned on, allowed and banners on.

Shahabuddin Vansiwala
  • 673
  • 1
  • 13
  • 24

0 Answers0