iPhone - 从 UILocalNotification 获取剩余时间
我想知道是否有办法从先前设置的本地通知中获取剩余时间。
假设我做了这样的事情:
//Creating Notification
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = someTime;
localNotif.alertBody = @"Your parking time will expire in 10 mins";
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
然后我完全关闭我的应用程序。我重新打开它,我想显示一些消息,说明通知启动还剩多少时间。
提前致谢。
I want to know if there's a way to get the remaining time from a Local Notification previously set.
Let's say I make something like this:
//Creating Notification
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = someTime;
localNotif.alertBody = @"Your parking time will expire in 10 mins";
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
So then I fully close my app. I reopen it and I want to show some message saying how much time is left for the notification to launch.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用 UIApplication ScheduledLocalNotifications 属性获取当前计划的通知的列表。也许得到这个并当时做一些数学?
You are supposed to be able to get a list of the currently scheduled notifications with the UIApplication scheduledLocalNotifications property. Maybe get this and do some math on the time?
当您调用以下方法时,如 [self timeRemaning];如果注册了任何通知,它会告诉您重命名需要多少秒。这仅适用于一个已注册的通知。
When you call the below method like [self timeRemaning]; it will give you how many seconds renaming if there is any notification registered. This will work only for one registered notification.