
我在info.plist中设置了“应用程序不在后台运行”,所以当用户点击主页按钮时,应用程序就会退出。
当我的[UIApplication -appWillTerminate:]调用时,我将调度64个本地通知到系统,它们都是非重复的。
但在iOS6.0.1的iPhone4上,这似乎需要很长的时间(6.17秒)。当我查看time profiler时,我发现这条曲线非常奇怪,它不需要太多的CPU时间,但它确实需要很多时间。
另外,当我查看调用树时,93%的时间花费在[UIApplication -scheduleLocalNotification:]上,时间范围如图所示。为什么?
下面是我生成通知的方式:
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];我是这样安排我的通知的:
-(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];
}发布于 2013-07-24 21:01:42
这将会有所帮助:
-(void)endProxyAndWriteToSystemLocalNotification {
[[UIApplication sharedApplication] setScheduledLocalNotifications:self.notifications];
}iOS 4.2及更高版本
有关详细说明,请阅读UIApplication类参考
发布于 2013-01-10 10:50:13
我认为问题在于您正在尝试安排64个本地通知。是否有理由在应用程序终止时执行所有这些操作?苹果的scheduleLocalNotification并没有被设计成在终止时被调用这么多次。
https://stackoverflow.com/questions/14250031
复制相似问题