Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find list of Local Notification the app has already set

My app allows users to set a number of reminders in the future. When the app lauches I want to know what reminders (notifications) have already been set.

Can I read back the notifications I have set or do I need to store in my app (e.g. Core Data or Plist)?

like image 284
Recycled Steel Avatar asked Jul 08 '13 16:07

Recycled Steel


People also ask

How many local notification are there in iOS?

But in iOS we can't schedule more than 64 notifications at a time.

What is local notification in Android?

Local notifications are scheduled by an app and delivered on the same device. They are suited for apps with time-based behaviors, such as calendar events. When you run your app on a device with Android OS 8.0 or above, Kony uses default channels that are mentioned in the localnotificationconfig.

Do local notifications work when app is closed?

Expected Behavior. The local notification should occur at the schedule time even if the app is closed.


2 Answers

UIApplication has a property called scheduledLocalNotifications which returns an optional array containing elements of type UILocalNotification.

UIApplication.shared.scheduledLocalNotifications 
like image 134
Scott Berrevoets Avatar answered Sep 16 '22 19:09

Scott Berrevoets


For Swift 3.0 and Swift 4.0

don't forget to do import UserNotifications

This is working for iOS10+ and watchOS3+ since the class UNUserNotificationCenter is not available for older versions (link)

let center = UNUserNotificationCenter.current()  override func viewWillAppear(_ animated: Bool) {     super.viewWillAppear(animated)      center.getPendingNotificationRequests { (notifications) in         print("Count: \(notifications.count)")         for item in notifications {           print(item.content)         }     } } 
like image 20
Frizzo Avatar answered Sep 17 '22 19:09

Frizzo