首页 文章

重新启动应用程序或关闭应用程序后,计划的UILocalNotification不会触发

提问于
浏览
0

我正在使用以下代码安排UILocalNotification:

UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60];
        notification.repeatInterval = NSMinuteCalendarUnit;
        notification.alertBody = [NSString stringWithFormat:@"Wurmprophylaxe für Lassy”];
        notification.alertAction = @"Wurmprophylaxe";
        //notification.userInfo = userInfo;
        notification.timeZone = [NSTimeZone localTimeZone];
        notification.soundName = UILocalNotificationDefaultSoundName;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

在我终止应用程序,重新启动应用程序或重新运行xcode之前,notofication会触发 . 简而言之,它并不存在 . 此外,即使应用程序再次运行,它也不会再次触发 . 应用程序是否位于前台并不重要 . 一旦终止,通知将停止,如果我列出本地通知,它将不再存在 . 似乎没有存储UILocalNotification . 如果应用程序位于前台,后台或根本不运行,则不会发送通知 .

为什么在应用启动之间删除它?

注意:如果我安排新通知,也会删除上一个通知 . 这完全是奇怪的 .

1 回答

  • 1

    这是正常行为 . 用户“终止”应用程序将积极清除系统为应用程序管理的任何进程 . (编辑:对于许多后台进程都是如此,但可能不适用于本地通知 . )通过Xcode重新加载新应用程序肯定会 .

    应用程序的正常过程是它首先进入后台状态,然后在后台由系统终止 . 系统管理的任务将继续,并在必要时重新唤醒应用程序 .

相关问题