What's a good way to manage the Local Notifications your app has scheduled?
Asked Answered
G

2

6

I'm diving into iOS development and have been working on an alarm clock app to become familiar with iOS platform and SDK. I'm using Local Notifications to handle my alarms, but I need some method of managing the Local Notifications I set so that they can be updated if I edit or remove any of the alarms associated with them. I figured out how I can unschedule a Local Notification using cancelLocalNotification: function after it's been scheduled, but I'm having a hard time figuring out how to retrieve the Local Notification object associated with the alarm that was edited or removed so that I can use that function. I should note that all of my alarm objects that are used to create the Local Notifications are being stored in a Core Data DB and their interface is defined as...

@interface Alarm :  NSManagedObject  
{
}

@property (nonatomic, retain) NSNumber * Snooze;
@property (nonatomic, retain) NSNumber * AlarmID;
@property (nonatomic, retain) NSString * Label;
@property (nonatomic, retain) NSDate * Repeat;
@property (nonatomic, retain) NSDate * Time;
@property (nonatomic, retain) NSNumber * Enabled;
@property (nonatomic, retain) NSString * Song;
@property (nonatomic, retain) NSString * Sound;

@end
  1. What's a good way to manage the Local Notifications my app schedules so that I can later retrieve those Local Notification objects and reschedule them if needed?
  2. Is there a way to retrieve the Local Notifications that have been scheduled by your app?
  3. If so, is there a way to identify them uniquely?

Thanks so much in advance for your help!

Gentry answered 9/8, 2010 at 17:43 Comment(0)
S
16

To answer question #2 use scheduledLocalNotifications, which will get back to you NSArray of all notifications scheduled for your app.

To answer question #3 use userInfo property of UILocalNotification class. It's a dictionary and you can save anything you want there.

Spiritualism answered 9/8, 2010 at 17:49 Comment(2)
This only allows you to efficiently find the database entry for any given notification. The other way around, finding the notification object for a given database entry, would require you to search through the scheduledLocalNotifications array. Is it possible to store a pointer in Core Data? Or is there no guarantee the notification remains at the same memory address? Not that searching through a small array is such a big deal.Unveiling
scheduledLocalNotifications only retrieve UILocalNotifications with property repeatInterval different from nil.Brassica
H
0
  1. You can retrieve all the local notifications your app has scheduled using the UIApplication classes scheduledLocalNotifications method.
Helix answered 6/11, 2010 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.