检测未确认的UILocalNotifications [英] detect unacknowledged UILocalNotifications

查看:80
本文介绍了检测未确认的UILocalNotifications的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎

didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

didReceiveLocalNotification:(UILocalNotification *)通知

仅在用户确认UILocalNotification时触发,例如通过滑动滑块或触摸iOS通知下拉菜单。

are only triggered if the user acknowledges the UILocalNotification, for example by swiping the slider or touching the entry in iOS's Notification pull-down.

是如果用户忽略UILocalNotification并通过简单地点击应用程序图标重新进入应用程序,有没有办法告诉UILocalNotification已经关闭?

Is there any way to tell that a UILocalNotification has gone off if the user ignores the UILocalNotification and re-enters the app by simply clicking on the app icon?

我应该提到这实际上仅适用于重复通知,因为可以通过观察总计数来检测非重复通知的触发。也就是说,当他们开火时,从 [[UIApplication sharedApplication] scheduledLocalNotifications] 消失。

I should mention that this really only applies to repeating notifications because the firing of non-repeating notifications can be detected by observing the total count. That is, when they fire, the vanish from [[UIApplication sharedApplication] scheduledLocalNotifications].

我正在寻找类似于..

I'm looking for something like..

[[UIApplication sharedApplication] unacknowledgedLocalNotifications]

唉,我找不到类似的东西。

Alas, I can't find anything like it.

推荐答案

嗯,你可以查看里面的预定通知 [[UIApplication sharedApplication] scheduledLocalNotifications] 。要查明计划的重复通知是否已触发,请访问 fireDate 属性,以查看为通知设置的初始日期。然后检查 repeatInterval 属性。

Well, you can check your scheduled notifications inside [[UIApplication sharedApplication] scheduledLocalNotifications]. To find out if a scheduled repeating notification has fired access the fireDate property to see what was the initial date set for the notification. Then check the repeatInterval property.

所以你有2个变量,一个是初始 NSDate ,比如说 2013 -05-08 12:00 ,第二个是重复间隔,让我们说每天。通过 [NSDate date] ,您将获得我所在的当前日期(在瑞典) 2013-05-09 22时45分。所以这意味着有一个用户没有采取行动的通知。

So there you have 2 variables, one is the initial NSDate, lets say 2013-05-08 12:00 and second is the repeat interval, lets say daily. And by doing a [NSDate date] you will get the current date which where I'm located (in Sweden) is now 2013-05-09 22:45. So this means that there is one notification the user has not acted on.

所以你需要创建一个方法来接受这些参数,然后从初始日期开始迭代查看在当前日期时间之前丢失了多少通知。

So you will need to create a method that will take these arguments and then iterate from the initial date to see how many notifications that have been missed until the current datetime.

您会发现 NSCalendar s dateByAddingComponents:toDate:options 有用。

这篇关于检测未确认的UILocalNotifications的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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