【发布时间】:2011-06-11 02:13:24
【问题描述】:
已修复 — 好的,找到了,有一个错误的 [[UIApplication sharedApplication] cancelAllLocalNotifications]; 在我没想到的时候被解雇了。
那是你的问题。
感谢大家的帮助,很抱歉这只是愚蠢的程序员综合症。
我已经像这样构建了我的本地通知:
- (void)scheduleNotification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
NSLog(@"%@", [NSDate date]);
notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
notif.alertBody = NSLocalizedString(@"Hello.", nil);
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
NSLog(@"Notification scheduled at %@", notif.fireDate);
[notif release];
}
}
正如预期的那样,我的调试日志会在 10 秒后输出正确的 fireDate。如果我不离开我的应用程序,我会收到一个成功的 application:didReceiveLocalNotification: 回调。
这里的问题是如果我按下按钮来安排此通知并按下主页按钮将其置于后台。如果我这样做,通知将永远不会触发,并且我永远不会从操作系统获得警报视图。
我在这里错过了什么明显的东西吗?我在此处和 Apple 文档中上下翻阅,感觉我遗漏了一些明显的东西。
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
请将您的解决方案添加为答案,因此该问题不再列在“未回答的问题”列表中,并且将来可能会帮助其他人找到解决问题的方法。
标签: objective-c ios cocoa-touch uikit uilocalnotification