多说无益,看代码:
/*
* 一个时间点(dateStr)之后的多少秒(period)提醒,提醒内容(title)
*
*/
-(void)useAlarmClock:(NSString*)dateStr andPeriod:(int)period andTitle:(NSString*)title
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
if (dateStr.length>16) {
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
}else{
[formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
}
NSDate *date = [formatter dateFromString:dateStr];
UILocalNotification *notification=[[UILocalNotification alloc] init];
notification.fireDate = [date dateByAddingTimeInterval:period];
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.soundName = @"ping.caf";
notification.alertBody = [NSString stringWithFormat:@"%@时间到了!",title];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

本文介绍如何使用Objective-C编程语言实现一个功能,即在指定时间点之后提醒用户某个事件的发生,通过设置日期格式、解析字符串日期并计算时间差,从而触发本地通知提醒。

被折叠的 条评论
为什么被折叠?



