【发布时间】:2013-09-10 03:46:13
【问题描述】:
我有 SQLite 数据库。
我想在日期更改时在数据库中插入行。
我只知道我应该使用UILocalNotification,但我不知道如何。
其他方法是在后台运行 NSTimer,但我不想这样做。
从我尝试过的教程中:
UIApplication* app = [UIApplication sharedApplication];
NSDate *date = [NSDate date];
// create the notification and then set it's parameters
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
if (notification)
{
notification.fireDate = date;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
notification.alertBody = @"DONE:";
// this will schedule the notification to fire at the fire date
[app scheduleLocalNotification:notification];
// this will fire the notification right away, it will still also fire at the date we set
[app presentLocalNotificationNow:notification];
}
但在我的应用程序中,它应该在数据库中插入应用程序是在后台还是在前台。插入应在日期更改时进行。
【问题讨论】:
-
为什么需要在日期更改的确切时间添加此行?如果您的应用在新的一天开始并且该行尚未添加,为什么不简单地添加一个新行?
-
NSTimer 仅在后台工作 10 分钟,最好根据您的要求使用 UILocalNotification。
-
不,我想在日期更改时插入.. 如果我按照你说的做,那么在早上 10 点我也必须向用户发送通知.. 应用程序处于后台或前台..
-
谢谢@AnandGautam,但是怎么做?
标签: iphone ios objective-c sqlite uilocalnotification