且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iPhone中的多个本地通知

更新时间:2023-02-26 21:31:22

只需要三个(或更多)本地通知并使用 scheduleLocalNotification:安排每个通知,问题是什么?
例如,这就是我在项目中所做的:

Just make three (or more) local notifications and schedule every one of them with scheduleLocalNotification:, what's the problem? For example this is what I did in my project:

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