我面临 scheduleLocalNotification 的性能问题。我正在尝试注册大量本地通知。这就像朋友的生日闹钟。为了测试,我尝试注册大约 300 条通知,但我的 iPhone4 花了 2 多分钟。(iPad2 4 秒,iPhone4S 8 秒)
这是一个代码。
-(void)setAllBirthdaysSchedule
{
Class cls = NSClassFromString(@"UILocalNotification");
if (cls == nil) {
return ;
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
if (prototypeNotification == nil) {
prototypeNotification = [[UILocalNotification alloc] init];
prototypeNotification.repeatCalendar = [NSCalendar currentCalendar];
prototypeNotification.repeatInterval = NSYearCalendarUnit;
prototypeNotification.timeZone = [NSTimeZone defaultTimeZone];
prototypeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
prototypeNotification.applicationIconBadgeNumber = 0;
prototypeNotification.alertBody = NSLocalizedString(@"Body", nil);
prototypeNotification.alertAction = NSLocalizedString(@"Action", nil);
}
NSArray* arr = [self getAllBirthday];
for (User* user in arr) {
UILocalNotification *notif = [prototypeNotification copy];
notif.fireDate = user.birthday;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
[pool release];
}