iOS实现定时本地推送功能 iPhone/iPad开发通过LocalNotification实现iOS定时本地推送功能

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

iOS实现定时本地推送功能 iPhone/iPad开发通过LocalNotification实现iOS定时本地推送功能

  2021-03-22 我要评论
想了解iPhone/iPad开发通过LocalNotification实现iOS定时本地推送功能的相关内容吗,在本文为您仔细讲解iOS实现定时本地推送功能的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:iOS定时推送本地通知,iOS每天4点推送本地通知,iOS本地推送通知,iOS每日定时推送本地通知,下面大家一起来学习吧。

通过iOS的UILocalNotification Class可以实现本地app的定时推送功能,即使当前app是后台关闭状态。 

可以实现诸如,设置app badgenum,弹出一个alert,播放声音等等,实现很简单 

UILocalNotification *notification=[[UILocalNotification alloc] init];
 if (notification!=nil) {
  NSDate *now=[NSDate new];
  notification.fireDate=[now dateByAddingTimeInterval:15];
  notification.timeZone=[NSTimeZone defaultTimeZone];
  notification.alertBody=@"定时推送通知!";
  notification.soundName = @"default";
  [notification setApplicationIconBadgeNumber:22];
  [[UIApplication sharedApplication] scheduleLocalNotification:notification];
 }


 写了一个demo,大家直接看demo就一目了然了,很方便,在适当场合使用还是蛮实用的~

源代码链接:https://github.com/andypan1314/LocalNotificationTest 

iOS 设置每天下午4点推送本地通知

UILocalNotification *notification=[[UILocalNotification alloc] init];
 if (notification!=nil) {//判断系统是否支持本地通知
  notification.fireDate = [NSDate dateWithTimeIntervalSince1970:16*60*60*24];//本次开启立即执行的周期
  notification.repeatInterval=kCFCalendarUnitWeekday;//循环通知的周期
  notification.timeZone=[NSTimeZone defaultTimeZone];
  notification.alertBody=@"哇哇哇";//弹出的提示信息
  notification.applicationIconBadgeNumber=0; //应用程序的右上角小数字
  notification.soundName= UILocalNotificationDefaultSoundName;//本地化通知的声音
//notification.alertAction = NSLocalizedString(@"美女呀", nil); //弹出的提示框按钮
  notification.hasAction = NO;
  [[UIApplication sharedApplication] scheduleLocalNotification:notification];
 }

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们