Reputation: 936
assume I scheduled 3 local notifications and when users opens app, three notifications have following states:
a) not displayed yet
b) displayed
c) displayed and user taps on this notification and come back to app.
How do i detect each one?
Upvotes: 1
Views: 605
Reputation: 114826
iOS 10 has introduced the UIUserNotificationCenter
, and deprecated the scheduling and delivery of local notifications via UIApplication
, so there are some differences depending on which method you are using. The deprecated methods still work on iOS 10, so if you are targeting iOS earlier than iOS10 then you can continue to use these methods, but you will get deprecation warnings.
For case a, a notification that hasn't yet been delivered, details of this notification are available by calling getPendingNotificationRequests
on an instance of UIUserNotificationCenter
(iOS 10) or by accessing the scheduledLocalNotifications
property on your app's UIApplication
instance (Prior to iOS 10)
For case b, a notification that has been delivered but that the user didn't interact with, no information is available.
For case c, the notification that the user tapped to launch the app, it depends on the state of the application and how the user interacts with the notification.
application:didFinishLaunchingWithOptions:
via the localNotification
key in the options dictionarydidReceiveLocalNotification
delegate method is called.application:handleActionWithIdentifier:forLocalNotification:completionHandler:
app delegate method is calledUpvotes: 1