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

编程入门 行业动态 更新时间:2024-10-19 17:34:25
本文介绍了当应用程序处于工作模式时,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不会触发

本文发布于:2023-11-27 07:31:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   模式   工作   UILocalNotification

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!