周期本地推送通知(闹钟功能)

上传人:xzh****18 文档编号:34790767 上传时间:2018-03-01 格式:DOCX 页数:4 大小:72.23KB
返回 下载 相关 举报
周期本地推送通知(闹钟功能)_第1页
第1页 / 共4页
周期本地推送通知(闹钟功能)_第2页
第2页 / 共4页
周期本地推送通知(闹钟功能)_第3页
第3页 / 共4页
周期本地推送通知(闹钟功能)_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《周期本地推送通知(闹钟功能)》由会员分享,可在线阅读,更多相关《周期本地推送通知(闹钟功能)(4页珍藏版)》请在金锄头文库上搜索。

1、初学iOS写些简单的笔记文章,希望对初学者有帮助; 下面是本地推送和周期设定的一些代码: 时间的编写与比较 /注意格式_weekdayUIApplication sharedApplication cancelAllLocalNotifications;NSArray *arr=NSArray allocinitWithObjects:“1“,“5“, nil;NSString*str=arr objectAtIndex:1;NSLog(“%d“,str intValue); /注意格式_optiontimeNSString *datestr=“2010-08-04 16:01:00“;NSD

2、ateFormatter *dateFormatter = NSDateFormatter alloc init;dateFormatter setDateFormat:“yyyy-MM-dd HH:mm:ss“;NSDate *date = dateFormatter dateFromString:datestr;NSArray *datearr=datestr componentsSeparatedByString:“ “;NSArray *timer=datearr1 componentsSeparatedByString:“:“;NSDate *now=NSDate date; /设置

3、时间与系统时间的比较if(now compare:date=NSOrderedSame) /系统时间等于设定时间NSCalendar *gregorian =NSCalendar currentCalendar;NSDateComponents * dateComps=gregorian components:NSWeekdayCalendarUnit fromDate:now;NSInteger datecount = dateComps weekday;NSDate *weekdaybegin = now addTimeInterval:-datecount*60*60*24;for(in

4、t i=0;iarr.count;i+)NSString *str=arr objectAtIndex:i;int weekday=str intValue;NSDate *date=weekdaybegin addTimeInterval:weekday*60*60*24;self creatmessage:date;else if (now compare:date=NSOrderedDescending) /系统时间晚于设定时间NSCalendar *gregorian =NSCalendar currentCalendar;NSDateComponents * dateComps=gr

5、egorian components:NSWeekdayCalendarUnit fromDate:now;NSInteger nowhour=dateComps hour;NSInteger nowmin=dateComps minute;NSInteger nowsecond=dateComps second;nowsecond=nowsecond+nowmin*60+nowhour*60*60;NSInteger optionhour=timer objectAtIndex:0 intValue;NSInteger optionmin=timer objectAtIndex:1 intV

6、alue;NSInteger optionsecond=timer objectAtIndex:2 intValue;optionsecond=optionsecond+optionmin*60+optionhour*60*60;NSInteger datecount = dateComps weekday;NSDate *weekdaybegin = now addTimeInterval:-datecount*60*60*24- nowsecond+optionsecond;for(int i=0;iarr.count;i+)NSString *str=arr objectAtIndex:

7、i;int weekday=str intValue;NSDate *date=weekdaybegin addTimeInterval:weekday*60*60*24;self creatmessage:date;else if (now compare:date=NSOrderedAscending) /系统时间早于设定时间NSCalendar *gregorian =NSCalendar currentCalendar;NSDateComponents * dateComps=gregorian components:NSWeekdayCalendarUnit fromDate:now

8、;NSInteger nowhour=dateComps hour;NSInteger nowmin=dateComps minute;NSInteger nowsecond=dateComps second;nowsecond=nowsecond+nowmin*60+nowhour*60*60;NSInteger optionhour=timer objectAtIndex:0 intValue;NSInteger optionmin=timer objectAtIndex:1 intValue;NSInteger optionsecond=timer objectAtIndex:2 int

9、Value;optionsecond=optionsecond+optionmin*60+optionhour*60*60;NSInteger datecount = dateComps weekday;NSDate *weekdaybegin = now addTimeInterval:-datecount*60*60*24- nowsecond+optionsecond;for(int i=0;iarr.count;i+)NSString *str=arr objectAtIndex:i;int weekday=str intValue;NSDate *date=weekdaybegin

10、addTimeInterval:weekday*60*60*24;self creatmessage:date; /推送通知设定的方法 -(void)creatmessage:(NSDate *)new UILocalNotification *notification=UILocalNotification allocinit;if(notification!=nil)NSDate *now=new;NSLog(“%“,now);notification.fireDate=now;notification.timeZone=NSTimeZone defaultTimeZone;notification.repeatInterval=kCFCalendarUnitWeek;notification.alertBody=“message“;notification.soundName=UILocalNotificationDefaultSoundName;notification.alertAction=NSLocalizedString(“wakeup“, nil); UIApplication sharedApplicationscheduleLocalNotification:notification;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号