3

已修复[[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:回调。

这里的小问题是如果我按下按钮来安排这个通知并点击主页按钮将它放在后台。如果我这样做,通知将永远不会触发,并且我永远不会从操作系统获得警报视图。

我在这里错过了什么明显的东西吗?我在这里和苹果文档上下看了看,感觉我错过了一些明显的东西。

任何帮助将不胜感激。谢谢。

4

3 回答 3

1

请参阅 Apple 文档中的示例:http: //developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1

难道没有将 timeZone 设置为 [NSTimeZone defaultTimeZone] 会导致问题吗?如果未设置 timeZone(默认为零),则假定为 GMT。

于 2011-06-11T02:27:00.560 回答
0

您是否尝试过将代码包装在后台任务中?

于 2011-06-11T02:16:22.793 回答
0

好的,找到它是什么,有一个错误 [[UIApplication sharedApplication] cancelAllLocalNotifications]; 进入后台时发送。

于 2012-08-10T22:51:45.563 回答