I want to receive a Local notification when my app is in foreground, when I tried with below code it never fires a notification, but when I entered app in background it did fired.
here is what I tried:
//Schedule a Local Notification func ScheduleNotification(timeInterval: Double, repeats: Bool, notificationBody:String, title:String){ let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: timeInterval, repeats: repeats) let center = UNUserNotificationCenter.current() let identifier = "UYLLocalNotification" let content = UNMutableNotificationContent() content.title = title content.body = notificationBody content.sound = UNNotificationSound.default() let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger) center.add(request, withCompletionHandler: { (error) in if let error = error { //Something went wrong print(error.localizedDescription) } }) } override func viewDidLoad() { super.viewDidLoad() if Currentcount < data.count { self.ScheduleNotification(timeInterval: 5.0, repeats: false, notificationBody: "You have \(data.count - Currentcount) notification", title: "Alert!") } } Any help would be appreciated Thanks.