4

가능한 중복 :
Schedule number of Local Notifications성능 문제 (로컬 알림 많은 수의)

내가 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]; 
} 
+0

운영자가 다시 열 수 있습니까? "중복"은 실제로 로컬 알림 제한을 처리하는 반면이 질문은 성능 문제를 해결합니다. – Mazyod

답변

1

예 오래된 장치에서는 로컬 알림을 등록하는 데 약간의 시간이 걸렸습니다. 배경 스레드에 등록하려고하십시오.

iOS에는 최대 64 개의 알림이 있으며 나머지는 삭제됩니다. 자세한 정보는 UILocalNotification 클래스 참조를보십시오.

+0

감사합니다. 나는 백그라운드 스레드에서 시도했지만, 홈 화면에 갔다가 장치가 거의 멈추고있다. 이상해. – samtaegi

+0

@samtaegi 실제로, 나는 그것을 또한 목격했다. runloop 당 하나의 알림을 처리하여 문제를 해결할 수있었습니다. 작업 대기열을 만들고 주 스레드에서 비동기 적으로 한 번에 하나의 작업 만 처리하면됩니다. 주 스레드가 초당 60 회 실행된다고 가정하면 주 스레드가 작업 할 수있는 시간 동안 균등하게로드를 분산시켜야합니다. – Mazyod