gpt4 book ai didi

objective-c - 应用程序在后台时不显示 iOS UILocalNotification

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:27:37 29 4
gpt4 key购买 nike

已修复 — 好吧,找到了,有一个错误的 [[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: 回调。

这里的小问题是,如果我按下按钮来安排此通知并按下主页按钮将其置于后台。如果我这样做,通知永远不会触发,我也永远不会从操作系统获得警报 View 。

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

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

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

会不会是没有将 timeZone 设置为 [NSTimeZone defaultTimeZone] 导致了问题?如果未设置时区(默认为零),则假定为格林威治标准时间。

关于objective-c - 应用程序在后台时不显示 iOS UILocalNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6313641/

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