ios本地添加提醒事件

来源:互联网 发布:linux vncviewer使用 编辑:程序博客网 时间:2024/06/06 04:46

多说无益,看代码:

/*

 * 一个时间点(dateStr)之后的多少秒(period)提醒,提醒内容(title)

 *

 */

-(void)useAlarmClock:(NSString*)dateStr andPeriod:(int)period andTitle:(NSString*)title

{

    NSDateFormatter *formatter = [[NSDateFormatteralloc] init];

    if (dateStr.length>16) {

        [formattersetDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    }else{

        [formattersetDateFormat:@"yyyy-MM-dd HH:mm"];

    }

    NSDate *date = [formatter dateFromString:dateStr];

    UILocalNotification *notification=[[UILocalNotificationalloc] init];

    notification.fireDate = [datedateByAddingTimeInterval:period];

    notification.timeZone=[NSTimeZonedefaultTimeZone];

    notification.soundName =@"ping.caf";

    notification.alertBody = [NSStringstringWithFormat:@"%@时间到了!",title];

    [[UIApplicationsharedApplication] scheduleLocalNotification:notification];

    

}



1 0
原创粉丝点击