0

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

}
4

2 に答える 2

5

これは役立ちます:

-(void)endProxyAndWriteToSystemLocalNotification {

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

iOS 4.2 以降

詳細については、UIApplication クラス リファレンスを参照してください。

于 2013-07-24T13:01:42.380 に答える
0

問題は、64のローカル通知をスケジュールしようとしていることだと思います。アプリの終了時にこれらすべてを行う理由はありますか?ApplesのscheduleLocalNotificationは、終了時に何度も呼び出されるようには設計されていません

于 2013-01-10T02:50:13.193 に答える