gpt4 book ai didi

iphone - scheduleLocalNotification 的性能问题(大量本地通知)

转载 作者:可可西里 更新时间:2023-11-01 06:11:17 25 4
gpt4 key购买 nike

我遇到了 scheduleLocalNotification 的性能问题。我正在尝试注册大量本地通知。这就像 friend 的生日闹钟。为了测试,我尝试注册大约 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];
}

最佳答案

是的,在旧设备上注册本地通知需要一些时间。尝试将注册放入后台线程。

请注意,iOS 中最多有 64 条通知,其余的将被丢弃。查看 UILocalNotification 类引用以获取更多信息。

关于iphone - scheduleLocalNotification 的性能问题(大量本地通知),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com