我已经在我的应用程序中实现了本地通知,我在以下场景中遇到了问题:
场景:应用程序启动,位置通知将在当前日期一周后显示在登录屏幕中,我已使用凭据登录,登录后双击设备的主页按钮(底部中心物理键)以调出最近使用的应用程序栏然后点击并按住应用程序图标以便能够杀死应用程序。杀死应用程序后,通知弹出窗口无需等待一周时间即可呈现
下面是代码:
- (void)applicationWillTerminate:(UIApplication *)application
{
    if (iPhoneClientConfig::getInstance()->getReminder() == RS_NONE) {
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
    }
    else {
        int daysToAdd;
        NSString *alertText;
        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
        if (iPhoneClientConfig::getInstance()->getReminder() == RS_MONTH) {
            daysToAdd = 60*60*24*30;
            alertText = [Localization getLanguage:@"reminder_message_month"];
            localNotification.repeatInterval =  NSMonthCalendarUnit;
            [self generateAlertNotifications:daysToAdd withtext:alertText ];
        } else if (iPhoneClientConfig::getInstance()->getReminder() == RS_DAY) {
            daysToAdd = 60*60*24;
            alertText = [Localization getLanguage:@"reminder_message_day"];
            localNotification.repeatInterval =  NSDayCalendarUnit;
        } else if (iPhoneClientConfig::getInstance()->getReminder() == RS_HOUR) {
            daysToAdd = 60*60;
            alertText = [Localization getLanguage:@"reminder_message_hour"];
            localNotification.repeatInterval =  NSHourCalendarUnit;
        } else {
            if (iPhoneClientConfig::getInstance()->getReminder() != RS_WEEK) {
                LOG.error("%s: Unexpetected reminder repeat interval in configuration, fall back to week",__FUNCTION__);
            }
            daysToAdd = 60*60*24*7;
            alertText = [Localization getLanguage:@"reminder_message_week"];
            localNotification.repeatInterval =  NSWeekCalendarUnit;
            [self generateAlertNotifications:daysToAdd withtext:alertText];
        }
        NSDate *today = [NSDate date];
        NSDate *newDate = [today addTimeInterval:daysToAdd];
         NSLog(@"newDate:%@",newDate);
        // Set up the fire time
        localNotification.fireDate = newDate;
        localNotification.timeZone = [NSTimeZone defaultTimeZone];
        // Notification details and Set the action button
        localNotification.alertBody = alertText;
        localNotification.alertAction = [Localization getLanguage:@"local_notif_alert"];
        localNotification.soundName = UILocalNotificationDefaultSoundName;
        //Schedule LocalNotification
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
        NSLog(@"local_notif_alert:%@",localNotification);
        [localNotification release];
    }
}
我在控制台中有开火日期和本地通知,如下所示:
Date:2012-09-01 10:49:08 +0000
local_notif_alert:<UIConcreteLocalNotification: 0xd006d20>{fire date = Saturday, September 1, 2012 4:19:08 PM India Standard Time, time zone = Asia/Kolkata (IST) offset 19800, repeat interval = NSWeekCalendarUnit, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Saturday, September 1, 2012 4:19:08 PM India Standard Time}