random
random

Reputation: 8608

UILocalNotification adding and removing

After my user logs in the app pulls down a list of their meetings and adds them as UILocalNotification.

Each time the user launches the app and logs in this happens.

Which of the following is better "practice" when it comes to doing this over and over:

  1. Pull all the location notifications with scheduledLocalNotifications then as I cycle through the downloaded meetings check to see if a local notification already exist for that meeting. If so, don't add it.

  2. Use cancelAllLocalNotifications to clear all the local notifications and add them over.

It seems that #1 would be the right way but I'm concerned that if I have a meeting at the same time as another (it happens), it will view it as already added and won't add the new one.

Upvotes: 0

Views: 352

Answers (2)

rickerbh
rickerbh

Reputation: 9913

Personally I would pull down the locations and check through them. It just feels tidier to me rather than destroying everything and creating it all again. Then again, #2 might be (negligibly) faster as you don't need to loop and check.

If you're concerned about #1 not matching where two meetings have the same time, you could add your own unique identifier to the UILocalNotification object via the userInfo property, and query this to see if the meeting is the same event, rather than basing it on the time of the notification.

Upvotes: 1

CuriousRabbit
CuriousRabbit

Reputation: 2221

If you have an unique token, say a UUID, for each meeting, the double-booking situation can be avoided. Put this token in the userInfo dictionary for the notification and then you can see precisely which meeting the notification is for. Comparison to determine the if this meeting has a notification queued already would best be done by this unique token, making sure the time of the meeting did not change.

Upvotes: 0

Related Questions