1

在我的应用程序中,我的朋友列表说:3 个朋友,这三个人都有生日详细信息。我需要安排本地通知以显示他们的生日警报。我知道并处理了本地通知,但我将如何处理这些多重通知?

我在“for循环”中设置触发日期。是否正确,请参阅代码。

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];

我想要什么,只有在这种方法中,我必须根据他们的日期为所有朋友设置通知。谁能告诉我哪里做错了,如果我遗漏了什么,请告诉我。

4

1 回答 1

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;
}
于 2012-06-13T09:13:37.867 回答