在我的应用程序中,我有朋友列表说:3个朋友,这三个都有生日详情。我需要安排本地通知,以显示他们的b'days警报。我知道并处理了本地通知,但我将如何处理这些多重通知?
我在“for loop”中设置了开火日期。这是正确的,请参阅代码。
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
NSDateFormatter *formatter = [[[NSDateFormatter alloc]init]autorelease];
for (int i = 0; i< [delegate.viewController.contactList count] ; i++) {
NSString *birthday = [[myArray objectAtIndex:i]objectForKey:@"birthday"];
[formatter setDateFormat:@"MM/dd/yyyy"];
NSDate *date = [formatter dateFromString:birthday];
localNotif.fireDate = [date dateByAddingTimeInterval:10];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
NSLog(@"local %@",localNotif.fireDate);
}
localNotif.applicationIconBadgeNumber = 1;
NSString *itemName = @“Friend Name";
NSDictionary *userDict = [NSDictionary dictionaryWithObjectAndKey:itemName,@"msg", nil];
localNotif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
我想要什么,在这种方法中我只需要根据他们的日期为所有朋友设置通知。任何人都可以告诉我我在哪里做错了,如果我遗失了什么,请通知我。
答案 0 :(得分:4)
只需制作三个(或更多)本地通知,并使用scheduleLocalNotification:
安排每个通知,问题是什么?
例如,这就是我在项目中所做的:
for (int i = 0; i < 6; i++) {
UILocalNotification *localNotification = [prototypeNotification copy];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:dates];
[notifications addObject:localNotification];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
}
<强> UPD 强>
// ...this goes earlier:
static NotificationController *sharedNotificationController = nil;
- (id) init
{
if (self = [super init]) {
notifications = [[NSMutableArray alloc] init];
prototypeNotification = [[UILocalNotification alloc] init];
prototypeNotification.repeatCalendar = [NSCalendar currentCalendar];
prototypeNotification.repeatInterval = NSMinuteCalendarUnit;
prototypeNotification.timeZone = [NSTimeZone defaultTimeZone];
prototypeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
prototypeNotification.applicationIconBadgeNumber = 0;
prototypeNotification.alertBody = NSLocalizedString(@"Body", nil);
prototypeNotification.alertAction = NSLocalizedString(@"Action", nil);
enabled_ = NO;
}
return self;
}