Ios 使用应用程序上次运行时的localNotification

Ios 使用应用程序上次运行时的localNotification,ios,objective-c,ios7,Ios,Objective C,Ios7,这是我当前的代码 NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendar NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)

这是我当前的代码

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小时。

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

您不需要对时区或日历执行任何操作,因为这在用户的设备上本地发生。

可能重复的