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