Schedule multiple events with NSTimer?
- by AWright4911
I have a schedule cache stored in a pList.
For the example below, I have a schedule time of April 13, 2010 2:00PM and Aril 13, 2010 2:05PM. How can I add both of these to a queue to fire on their own?
item 0
-Hour
--14
-Minute
--00
-Month
--04
-Day
--13
-Year
--2010
item 1
-Hour
--14
-Minute
--05
-Month
--04
-Day
--13
-Year
--2010
this is how I am attempting to schedule multiple events to fire at specific date / time.
-(void) buildScheduleCache
{
MPNotifyViewController *notifier = [MPNotifyViewController alloc] ;
[notifier setStatusText:@"Rebuilding schedule cache, this will only take a moment."];
[notifier show];
NSCalendarDate *now = [NSCalendarDate calendarDate];
NSFileManager *manager = [[NSFileManager defaultManager] autorelease];
path = @"/var/mobile/Library/MobileProfiles/Custom Profiles";
theProfiles = [manager directoryContentsAtPath:path];
myPrimaryinfo = [[NSMutableArray arrayWithCapacity:6] retain];
keys = [NSArray arrayWithObjects:@"Profile",@"MPSYear",@"MPSMonth",@"MPSDay",@"MPSHour",@"MPSMinute",nil];
for (NSString *profile in theProfiles)
{
plistDict = [[[NSMutableDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",path,profile]] autorelease];
[myPrimaryinfo addObject:[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:
[NSString stringWithFormat:@"%@",profile],
[NSString stringWithFormat:@"%@",[plistDict objectForKey:@"MPSYear"]],
[NSString stringWithFormat:@"%@",[plistDict objectForKey:@"MPSMonth"]],
[NSString stringWithFormat:@"%@",[plistDict objectForKey:@"MPSDay"]],
[NSString stringWithFormat:@"%@",[plistDict objectForKey:@"MPSHour"]],
[NSString stringWithFormat:@"%@",[plistDict objectForKey:@"MPSMinute"]],
nil]forKeys:keys]];
profileSched =
[NSCalendarDate dateWithYear:[plistDict objectForKey:@"MPSYear"]
month:[plistDict objectForKey:@"MPSMonth"]
day:[plistDict objectForKey:@"MPSDay"]
hour:[plistDict objectForKey:@"MPSHour"]
minute:[plistDict objectForKey:@"MPSMinute"]
second:01
timeZone:[now timeZone]];
[self rescheduleTimer];
}
NSString *testPath = @"/var/mobile/Library/MobileProfiles/Schedules.plist";
[myPrimaryinfo writeToFile:testPath atomically:YES];
}
-(void) rescheduleTimer
{
timer = [[NSTimer alloc] initWithFireDate:profileSched
interval:0.0f
target:self
selector:@selector(theFireEvent)
userInfo:nil
repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
}