我正在基于时间提醒应用程序。其中用户输入他的提醒和提醒的时间。问题是如何持续比较当前时间和用户定义的时间。任何示例代码将极大地帮助。因为我被困在这一点上。在iPhone中创建基于时间的提醒应用程序
0
A
回答
15
比较当前时间和用户定义的时间并不是正确的设计模式。
UIKit中提供NSLocalNotification对象,它是你的任务更高层的抽象。
下面是创建和在已选定的时间安排本地通知代码剪断:
UILocalNotification *aNotification = [[UILocalNotification alloc] init];
aNotification.fireDate = [NSDate date];
aNotification.timeZone = [NSTimeZone defaultTimeZone];
aNotification.alertBody = @"Notification triggered";
aNotification.alertAction = @"Details";
/* if you wish to pass additional parameters and arguments, you can fill an info dictionary and set it as userInfo property */
//NSDictionary *infoDict = //fill it with a reference to an istance of NSDictionary;
//aNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:aNotification];
[aNotification release];
另外,一定要设置你的AppDelegate双方在启动和在正常本地通知作出回应,应用程序的运行时间(如果你希望收到即使应用程序在前台):在Apple Developer Documentation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *aNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey];
if (aNotification) {
//if we're here, than we have a local notification. Add the code to display it to the user
}
//...
//your applicationDidFinishLaunchingWithOptions code goes here
//...
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
//if we're here, than we have a local notification. Add the code to display it to the user
}
更多细节。
2
为什么不使用NSLocalNotification
您可以指定的时间设置,就像日历事件。另外,您可以添加日历事件的用户日历EKEventKit
教程event kit。
相关问题
- 1. 基于计时器的iPhone应用程序提醒
- 2. 在iphone应用程序提醒
- 3. 时间提醒应用程序C#
- 4. 如何创建一段时间提醒提醒我在iPhone中提醒我30分钟
- 5. Adobe AIR/FlashBuilder 4.6:在Android应用程序中创建提醒
- 6. 在Android应用程序中创建提醒
- 7. 在NodeJs中建模基于时间的应用程序
- 8. iPhone如何:开发在通话时间提醒您的应用程序
- 9. 创建API,用于iPhone应用程序
- 10. 我应该多长时间提醒用户“评价应用程序”(iPhone)?
- 11. 基于iPhone/iPad的应用程序创建文本内容
- 12. iPhone应用程序在某个特定时间“醒来”
- 13. 基于iPhone应用程序创建Dashbord小部件(使用XCode?)
- 14. 基于时间的提醒在Django中的电子邮件
- 15. 如何在iPhone日历上创建提醒和商店提醒
- 16. 想要在iphone应用程序中添加提醒
- 17. 在iPhone应用程序中创建.swf
- 18. 启动iPhone/iPad应用程序时提醒一次
- 19. 推送通知提醒打开iPhone时解锁应用程序
- 20. 在应用程序处于后台时显示sceen提醒
- 21. Android提醒应用程序
- 22. Android应用程序提醒
- 23. 提醒应用程序
- 24. 提醒应用程序
- 25. iPhone:如何创建在特定时间自动调用的iPhone应用程序
- 26. 以编程方式在iPhone中创建提醒...?
- 27. 创建类似Facebook的时间轴的tableview ... iPhone应用程序
- 28. iPhone应用程序中的每日提醒选项
- 29. iPhone原生应用程序中的提醒功能
- 30. 在创建字段时提醒用户
你可以从线程帮助http://stackoverflow.com/questions/949416/how-to-compare-two-dates-in-objective-c – Ali3n 2012-01-17 10:04:42
我希望该方法将持续运行,这将方法就像位置管理器的didupdatetolocation一样被调用 – 2012-01-17 10:13:50