当应用程序处于工作模式时,UILocalNotification不会触发 [英] UILocalNotification not firing when the app is in working mode

查看:157
本文介绍了当应用程序处于工作模式时,UILocalNotification不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于本地通知无法正常启动的原因有很多问题此处那里还有几个问题,当应用程序处于后台状态时,为什么不触发本地通知我也经历了​​他们

There are quite a few questions on why local notification is not firing properly here and there,also there are several questions on why local notification is not firing when the application is in background state which I have also gone through them.

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

But to my surprise I haven't found any notification post related to foreground state or in active state,i.e. in my app I am facing this strange issue,i.e. local notification fires when the app enters background mode and it doesn't fire when the app is in active state or in foreground mode,to my surprise again,even after fire date set for notification is expired,immediately after entering background,the notification fires.

编辑

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

Also another issue I am facing is the alert is not firing,i.e. the alert action we write in didReceive local notification method,here is the implementation code:

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

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

And here is that showReminder method which is present in another controller i.e.:

//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中提问或发帖。

Sorry if this issue doesn't require a question or post in stackoverflow.

任何人都请发表您的建议,我们很高兴收到任何帮助!

Any one please post your suggestions and any help is gladly appreciated!

提前全部谢谢:)

推荐答案

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

If the application is active then you will not recieve any sound, badge or alert, however the application delegate application:didReceiveLocalNotification: will be called

来自 apple docs


如果应用程序最重要且可见当系统提供
通知时,不显示任何警报,没有图标标记,并且没有播放声音
。但是,应用程序:didReceiveLocalNotification:如果应用程序委托实现它,则调用

UILocalNotification实例传递给此方法,
委托可以检查其属性或访问
userInfo字典中的任何自定义数据。

If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.

这篇关于当应用程序处于工作模式时,UILocalNotification不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆