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

时间:2012-06-27 05:57:51

标签: iphone uilocalnotification foreground

关于为什么本地通知没有正确触发herethere,有很多问题,当应用程序处于后台状态时,还有几个问题解释为什么本地通知没有触发也经历了them

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

修改

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

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

这是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];
}

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

任何人都请发表你的建议,很高兴得到任何帮助!

提前感谢所有人:)

1 个答案:

答案 0 :(得分:6)

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

来自apple docs

  

如果应用程序是最重要的,并且在系统交付时可见   通知,没有显示警报,没有图标标记,没有声音   玩过的。但是,应用程序:didReceiveLocalNotification:是   如果应用程序委托实现它,则调用它。该   UILocalNotification实例传递给这个方法,并且   委托可以检查其属性或访问来自的任何自定义数据   userInfo字典。