UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil) {
NSLog(@">> support local notification");
notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:10];
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.alertBody=@"该去吃晚饭了!";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
UILocalNotification需要4.0版本支持!!
应用程序启动后,当10秒钟过去后,如果应用还是在前台运行,而且应用委托实现- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification方法,
则会进入该函数;
如果10秒过后,应用在后台或,则会弹出alert框提示用户;
注意: 对本地通知的数量限制,iOS最多允许最近本地通知数量是64个,超过限制的本地通知将被iOS忽略。
更详细的代码见官方文档:《Scheduling, Registering, and Handling Notifications》,或则查阅UILocalNotification,可以设置比如声音,比如用户定义数据等。