我們已經做了類似於你的問題的東西,但我不知道它會幫助你或不..只是嘗試這個** NSWeekdayCalendarUnit **我建議你只是指我的答案。
NSCalendar * gregCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponent = [gregCalendar components:NSYearCalendarUnit|NSWeekCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
NSArray *dobArray = [NSArray arrayWithObjects:@"02-08-2014", @"10-08-2014", @"14-08-2014", @"15-08-2014", @"16-08-2014", @"17-08-2014", @"18-08-2014", @"22-08-2014", @"28-08-2014", @"29-08-2014",nil];
NSArray *messagesArray = [NSArray arrayWithObjects:@"Literacy And Numeracy workshop for parents and children", @"raksha Bandhan", @"Tri Colour Dat(School celebration)", @"Independence day (School Holiday)", @"PTM/Book Exhibition", @"Janmastami", @"Parsi New Year- School Holiday", @"Clown Day", @"Eco Friendly Ganesha-School Holiday", @"Ganesh Chaturthi-School Holiday",nil];
for (NSString *dobStr in dobArray)
{
NSArray *components = [dobStr componentsSeparatedByString:@"-"];
if(components.count>2) {
NSInteger aDay = [[components objectAtIndex:0] integerValue];
NSInteger aMonth = [[components objectAtIndex:1] integerValue];
// NSInteger aYear = [[components objectAtIndex:2] integerValue];
if(aDay == [dateComponent day] && aMonth == [dateComponent month]) { // dob is here
[dateComponent setDay:aDay];
[dateComponent setMonth:aMonth];
[dateComponent setYear:[dateComponent year]];
[dateComponent setHour:16];
[dateComponent setMinute:54];
UIDatePicker *dp = [[UIDatePicker alloc] init];
[dp setDate:[gregCalendar dateFromComponents: dateComponent]];
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSInteger index = [dobArray indexOfObject:dobStr];
// [notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]];
[notification setAlertBody:[messagesArray objectAtIndex:index]];
[notification setFireDate:dp.date];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];
return YES;
}
}
}
您是否檢查過您的specificDate變量每次都獲取不同的日期? – iHulk 2014-09-25 11:01:32
是的,我檢查它是不同的每一次。 – 2014-09-25 11:09:11
你能告訴我們天陣嗎? – karthikeyan 2014-09-25 11:13:24