gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:09:41 26 4
gpt4 key购买 nike

我在我的应用程序中实现了本地通知,我在以下情况下遇到了问题:

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

代码如下:

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

最佳答案

当然。一旦安排好,本地通知就有了自己的生命周期。
这是你必须做的:打电话

[[UIApplication sharedApplication] cancelAllLocalNotifications];

例如在 applicationWillTerminate: 中。

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

关于iphone - 杀死应用程序后显示本地通知弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12107046/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com