本地通知停止出现?

Posted

技术标签:

【中文标题】本地通知停止出现?【英文标题】:Local notification stopped appearing? 【发布时间】:2012-05-26 10:02:33 【问题描述】:

我最近为客户端做了一个包含本地通知的应用程序。在原始版本中,通知工作得非常好。但是当客户端尝试发布另一个版本时,只更改了图像和数据库资源,没有更改代码,通知停止工作。现在我一直在尝试调试代码,但一无所获。一切似乎都很好,但没有通知。同时,如果我运行早期的构建,它会完美运行。你能帮我看看有什么问题吗?非常感谢您的宝贵时间。

NSTimeInterval diffTimeIntervalSinceNow = timeInterval; //time-interval after which notification should appear


    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object
    [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:diffTimeIntervalSinceNow]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
    //[localNotification setRepeatInterval:notificationInterval];

    [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
    [localNotification setAlertBody:alertBody]; //Set the message in the notification from the textField's text
    [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
    [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
    [localNotification release];

这是我一直在使用的代码。但这与在早期版本中运行的代码完全相同。

【问题讨论】:

【参考方案1】:

我更正了您的代码:- 试试这个:- 在按钮操作中或在任何方法中

  [[UIApplication sharedApplication] cancelAllLocalNotifications];
       NSTimeInterval diffTimeIntervalSinceNow = timeInterval; //time-interval after which notification should appear


            UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object
            [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:diffTimeIntervalSinceNow]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
            //[localNotification setRepeatInterval:notificationInterval];

            [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
            [localNotification setAlertBody:alertBody]; //Set the message in the notification from the textField's text
            [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
            [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1


            [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
            [localNotification release];

为此工作:- 在 App 委托中检查此方法是否获取某些事件

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification



要取消所有通知,请在

中使用

【讨论】:

没有任何改变。我猜代码没问题,因为我将两个类都与“fileMerge”进行了比较,根本没有区别。【参考方案2】:

可能是你的客户端也修改了alertBody,新的alertBody的长度太长了?

【讨论】:

以上是关于本地通知停止出现?的主要内容,如果未能解决你的问题,请参考以下文章

在特定时间停止 iOS 本地通知

停止本地通知

添加 FCM 支持后,本地通知在 iOS 上停止工作

当应用程序从后台删除时停止本地通知

应用程序停止时如何在 Android 中获取本地通知?

本地通知 UNTimeIntervalNotificationTrigger triggerWithTimeInterval 每 1 分钟触发一次 如何停止