杀死应用程序后会显示本地通知弹出窗口

时间:2012-08-24 09:52:23

标签: iphone ios uilocalnotification

我在我的应用程序中实现了本地通知,我在下面的场景中遇到了一个问题:

场景:应用程序已启动,将创建位置通知,以便在登录屏幕的当前日期一周后显示,我已使用凭据登录并在双击设备的主页按钮(底部中心物理键)后登录打开最近使用的应用程序栏,然后点击并按住应用程序图标,以便能够终止应用程序。杀死应用程序后,会显示通知弹出窗口而不等待一周的时间

以下是代码:

- (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}

1 个答案:

答案 0 :(得分:2)

当然。一旦安排好,本地通知就有自己的生命 这就是你要做的事情:致电

[[UIApplication sharedApplication] cancelAllLocalNotifications];

例如在applicationWillTerminate:中。

对于意外通知过早出现:NSLog通知详细信息并确保您获得正确的安排。

相关问题