简体   繁体   中英

iOS : Handle all the uilocalnotification on click of one notification or app icon

How do i handle (open alert for) all the UILocalNotification on click of one notification since apple clears other notification from notification center on click of one notification...also if the user opens the app ignoring the notifications in notification center, how do i handle(open UIAlertView for) them as well? i have seen this working perfectly in Calminder app

You can use [[UIApplication sharedApplication] scheduledLocalNotifications]; to get all the notifications that are previously scheduled. This method returns an NSArray instance so you can run a for loop to handle these:

for (UILocalNotification *notification in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
    // Handling codes goes here.
}

If you wants to have some extra informations in the notification you can use the userInfo property. It is a dictionary to store additional informations along the notification. You can set it like this:

notification.userInfo = // The dictionary goes here.

So now you can do this:

for (UILocalNotification *notification in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
    NSDictionary *userInfo = notification.userInfo;
    // Handling codes goes here. Now you can use the user info dictionary to
    // get what you stored into the userInfo dictionary when you are
    // initializing the user info.
}

After this you can get all the informations and you can present it in an UIAlertView .

To call these codes above at app's launch you can use two methods:

-application:didFinishLaunchingWithOptions:

or

-applicationDidBecomeActive:

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM