【问题标题】:UILocalNotification not firing when the app is in working mode当应用程序处于工作模式时,UILocalNotification 不会触发
【发布时间】:2012-06-28 12:46:57
【问题描述】:

关于为什么本地通知没有正确触发here和there有很多问题,还有一些关于为什么当应用程序处于后台状态时本地通知没有触发的问题,我也经历过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 中发帖。

任何人请发表您的建议,我们很乐意提供任何帮助!

提前谢谢大家:)

【问题讨论】:

    标签: iphone uilocalnotification foreground


    【解决方案1】:

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

    来自apple docs

    如果应用程序在系统交付时最重要且可见 通知,不显示警报,没有标记图标,也没有声音 玩过的。但是, application:didReceiveLocalNotification: 是 如果应用程序委托实现它,则调用它。这 UILocalNotification 实例被传递到这个方法中,并且 委托可以检查其属性或从 用户信息字典。

    【讨论】:

    • 感谢Omar先生的回答。但是在我的应用程序中,如果用户正在使用该应用程序,如果他/她没有提示他/她,那么构建我的应用程序没有任何意义: (
    • @EshwarChaitanya application:didReceiveLocalNotification 被调用,如果你想要一个警报,为什么不在那里显示一个警报?
    • @janusfidel 实际上没有显示警报,这是我在硬币的另一面遇到的另一个问题:(
    • @EshwarChaitanya 如果这是另一个问题,您可能需要编辑您的问题并在显示 UIAlertView 时发布代码 :)
    • @OmarAbdelhafith 这没有被调用,这就是没有显示警报的原因
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多