打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
iOS 定时发本地push 实现
  1. //取消之前所有的本地通知  
  2.     [[UIApplication sharedApplication] cancelAllLocalNotifications];  
  3.       
  4.     //清空 icon数量  
  5.     [UIApplication sharedApplication].applicationIconBadgeNumber = 0;  
  6.       
  7.       
  8.     //启动本地通知  
  9.     UILocalNotification *notification=[[UILocalNotification alloc] init];  
  10.     if (notification!=nil)  
  11.     {  
  12.         //现在的时间  
  13.         NSDate *now=[NSDate date];  
  14.           
  15.           
  16.         //获得系统日期  
  17.         NSCalendar  * cal=[NSCalendar  currentCalendar];  
  18.         NSUInteger  unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;  
  19.         NSDateComponents * conponent= [cal components:unitFlags fromDate:now];  
  20.         NSInteger year=[conponent year];  
  21.         NSInteger month=[conponent month];  
  22.         NSInteger day=[conponent day];  
  23.         //NSString *  nsDateString= [NSString  stringWithFormat:@"%4d年%2d月%2d日",year,month,day];  
  24.           
  25.    
  26.           
  27.         //获得当天的12:00  时间  
  28.         NSString  * nsStringDate12 =  [NSString  stringWithFormat:@"%d-%d-%d-%d-%d-%d",  
  29.                             year, month,day, 12, 0, 0  ];  
  30.           
  31.         //根据时间字符串获得NSDate  
  32.         NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];  
  33.         [dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];  
  34.         NSDate  * todayTwelve=[dateformatter dateFromString:nsStringDate12];  
  35.           
  36.         //然后比较  now跟  todayTwelve那个大,如果已经过了12点,那就设置明天12点  
  37.         NSComparisonResult   dateResult =  [now  compare:todayTwelve ];  
  38.         if (dateResult ==  NSOrderedDescending  )  
  39.         {  
  40.             NSDate  *  tomorrowTwelve =  [todayTwelve  dateByAddingTimeInterval: 24 * 60 * 60];  
  41.               
  42.             notification.fireDate =  tomorrowTwelve;  
  43.         }  
  44.         else  
  45.         {  
  46.             notification.fireDate= todayTwelve;  
  47.         }  
  48.         notification.repeatInterval = kCFCalendarUnitDay;  
  49.         notification.timeZone=[NSTimeZone defaultTimeZone];  
  50.         notification.applicationIconBadgeNumber = 1;  
  51.    
  52.         notification.alertBody=@"今天还没上线,好多奖励没领呢";  
  53.    
  54.         notification.alertAction = @"打开";  
  55.         [[UIApplication sharedApplication]   scheduleLocalNotification:notification];  
  56.         [notification release];  
  57.     }  
  58.   
  59. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification  
  60. {  
  61.     NSLog(@"获得本地通知");  
  62.       
  63.       
  64.     //点击提示框的打开  
  65.     application.applicationIconBadgeNumber = 0;  
  66.       
  67.       
  68. }  



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
为乌克兰搭建“核保护伞”?战后欧洲安全的先例与可能性 | 国政学人
昨天在家看电视,对门35岁的美女来敲门,穿着浴袍像是刚洗完澡的样子,她向屋里望去,随机竟提出这种请求
学会9个说话万能公式,20个沟通技巧,真的会说话了
俄罗斯是什么样的生活?一个住了8年的中国人的描述
哈尔滨731罪证陈列馆‍,“中国人是出色的实验材料”
萧朗先生笔下的禽鸟图
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服