【问题标题】:UILocalNotification Scheduling with Repeat for 10AM GMT IssueUILocalNotification 调度与 10AM GMT 问题的重复
【发布时间】:2023-03-16 01:40:01
【问题描述】:

如果这是一个绝对菜鸟问题,我很抱歉,但我无法从文档或其他堆栈问题中找出这个问题 -

如何将 NSDate 对象设置为格林威治标准时间上午 10:00?我问的原因是这个 - 我想设置一个在格林威治标准时间每天上午 10:00 发生的本地通知。

我认为以下是正确的:

    NSDateComponents *comps = [[NSDateComponents alloc]init];
[comps setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

[comps setYear:2011];
[comps setMonth:1];
[comps setWeek:1];
[comps setDay:1];
[comps setHour:10];
[comps setMinute:52];
[comps setSecond:0];

NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSDate *date = [gregorian dateFromComponents:comps];
[comps release];

UILocalNotification *notif = [[UILocalNotification alloc]init];

notif.fireDate = date;
notif.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
notif.alertBody = @"New Challenges are available in Halo: Reach.\n\n Give them a look over with Halo Reach Challenges!";
notif.alertAction = @"Show Me";
notif.applicationIconBadgeNumber = 5;
notif.repeatInterval = NSDayCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];

不幸的是,这不会触发。任何帮助将不胜感激:)

【问题讨论】:

    标签: iphone objective-c nsdate uilocalnotification


    【解决方案1】:

    只要您的应用正在运行,通知就会直接发送到您的应用。您需要设置一个处理程序(在 appDelegate 中)并自己显示消息。当应用未运行时,应显示通知。

    【讨论】:

    • 好的。我假设 UILocalNotification 文档中会链接一个协议参考。我所要做的就是显示一个带有预期消息的 UIAlertView,对吗?
    • 好的,如果我将它设置为过去的日期,并重复播放...它会立即触发,但重播间隔应该仍然有效,对吧?还是我必须得到今天的日期,拆分它并添加一天?
    • 文档中明确提到了前者(它会在过去的日期立即触发)。然而,没有注意到重复发生了什么。我希望它们能够正常运行(也就是说,独立于过去或未来的原始存在),但这应该很容易检查。
    • 是的,它按预期工作。我用 NSMinuteTimeInterval 对其进行了测试。感谢你的帮助。不过,我决定不显示 UILocalNotification - 该应用程序非常非常……专注,而且我知道我的用户也非常专注。如果他们不想检查数据,他们就不会打开应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    相关资源
    最近更新 更多