【问题标题】:localNotification using the app last run time使用应用程序上次运行时间的 localNotification
【发布时间】:2014-07-03 12:12:45
【问题描述】:

这是我当前的代码

NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendar
    NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year, month, day,hour and minutesfor today's date
    [components setHour:15];
    [components setMinute:4];

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

    localNotification.fireDate = [calendar dateFromComponents:components];
    localNotification.alertBody = @"Come back for more new stuff!";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

我希望将触发日期设置为应用程序上次运行时间的 12 小时。

【问题讨论】:

标签: ios objective-c ios7


【解决方案1】:

在应用启动时安排通知,日期如下:[NSDate dateWithTimeIntervalSinceNow:60*60*12]

您无需对时区或日历做任何事情,因为这发生在用户设备的本地。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 2017-06-07
    • 2017-02-11
    相关资源
    最近更新 更多