MeloS
MeloS

Reputation: 7938

UIApplication -scheduleLocalNotification: very slow when called by UIApplication -appWillTerminate:

time profiler of my app when i press home button

I set the "application does not run in background" in my info.plist, so when user tap home button, app quits.

When my [UIApplication -appWillTerminate:] called, I will schedule 64 local notifications to system, all of them are non-repeating.

but that take a seemingly long time(6.17 seconds) on a iPhone4 with iOS6.0.1. When I look at the time profiler, I found that the curve is very strange, it don't take much CPU time, but it do take a lot of time.

Also when I look at the call tree, 93% of the time is spent on [UIApplication -scheduleLocalNotification:] in the time range showed in the image. Why?

This is how I generate my notifications:

UILocalNotification *n = [[[UILocalNotification] alloc] init] autorelease];
n.alertBody = @"some body";
n.hasAction = YES;
n.alertAction = @"some action";
n.fireDate = @"some date";
n.repeatInterval = 0;
n.soundName = @"my sound"
n.userInfo = aDictionaryWithAStringAbount10CharacterLongAnd2NSNumber.
[self.notifications addObject:n];

This is how I schedule my notifications:

-(void)endProxyAndWriteToSystemLocalNotification
{
        _proxying = NO;
        NSDate *dateAnchor = [NSDate date];

        NSEnumerator *enumerator = [self.notifications objectEnumerator];
        NSInteger i = 0;
        while (i < maxLocalNotifCount) {
            UILocalNotification *n = [enumerator nextObject];
            if (!d) {
                break;
            }

            if ([n.fireDate timeIntervalSinceDate:dateAnchor] >= 0) {
                [[UIApplication sharedApplication] scheduleLocalNotification:n];
                i++;
            }
        }

        [self.notificationDatas removeAllObjects];

}

Upvotes: 0

Views: 779

Answers (2)

unforseen
unforseen

Reputation: 66

This would help:

-(void)endProxyAndWriteToSystemLocalNotification {

    [[UIApplication sharedApplication] setScheduledLocalNotifications:self.notifications];
}

iOS 4.2 and later

read UIApplication Class Reference for detailed description

Upvotes: 5

Stephen
Stephen

Reputation: 1446

I think the problem is that you are trying to schedule 64 local notifications. Is there a reason to do all of these on app termination? Apples scheduleLocalNotification was not designed to be called so many times on termination

Upvotes: 0

Related Questions