4

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

1 に答える 1

1

はい、古いデバイスでは、ローカル通知を登録するのに時間がかかりました。登録をバックグラウンド スレッドに入れてみてください。

iOS には最大 64 個の通知があり、残りは破棄されることに注意してください。詳細については、UILocalNotification クラス リファレンスを参照してください。

于 2012-10-09T09:24:11.703 に答える