当应用程序处于工作模式时,UILocalNotification不会触发

Esh*_*nya 2 iphone foreground uilocalnotification

关于为什么本地通知在这里那里没有正确启动的问题有很多问题,当应用程序处于后台状态时,还有几个问题解释为什么本地通知没有触发,我也经历了这些问题.

但令我惊讶的是,我没有找到任何与前景状态或活动状态相关的通知帖子,即在我的应用程序中我面临这个奇怪的问题,即当应用程序进入后台模式时本地通知会触发,并且当应用程序进入后台模式时它不会触发应用程序处于活动状态或前台模式,令我惊讶的是,即使在通知设置的开启日期到期后,进入后台后,通知也会立即触发.

编辑

我面临的另一个问题是警报没有触发,即我们在didReceive本地通知方法中编写的警报操作,这里是实现代码:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{
    application.applicationIconBadgeNumber = 0;
    NSString *reminderText = [notification.userInfo objectForKey:addViewController.textField.text];
    [self.addViewController showReminder:reminderText];
}
Run Code Online (Sandbox Code Playgroud)

这是showReminder方法,它存在于另一个控制器中,即:

//Notification alert
- (void)showReminder:(NSString *)text
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reminder" message:text delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];

    UIImage *image= [UIImage imageNamed:@"icon@2x.png"];
    [imageView setImage:image];

    [alertView addSubview:imageView];
    [imageView release];

    [alertView show];
    [alertView release];
}
Run Code Online (Sandbox Code Playgroud)

很抱歉,如果此问题不需要在stackoverflow中提问或发帖.

任何人请发表您的建议,任何帮助很高兴!

在此先感谢所有:)

Oma*_*ith 6

如果应用程序处于活动状态,则您将不会收到任何声音,徽章或警报,但application:didReceiveLocalNotification:会调用应用程序代理

来自苹果文档

如果应用程序在系统发送通知时最重要且可见,则不会显示警报,也不会标记图标,也不会播放任何声音.但是,如果应用程序委托实现它,则调用application:didReceiveLocalNotification :. UILocalNotification实例将传递到此方法,并且委托可以检查其属性或从userInfo字典访问任何自定义数据.