CarmeloS CarmeloS - 1 year ago 135
iOS Question

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

, 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.

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:

_proxying = NO;
NSDate *dateAnchor = [NSDate date];

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

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

[self.notificationDatas removeAllObjects];


Answer Source

This would help:

-(void)endProxyAndWriteToSystemLocalNotification {

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

iOS 4.2 and later

read UIApplication Class Reference for detailed description

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download