FIXED— 好的,找到了,有一个错误[[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 文档中的示例:http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1 http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1
难道是没有将 timeZone 设置为 [NSTimeZone defaultTimeZone] 导致了问题吗?如果未设置时区(默认为 nil),则假定为 GMT。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)