当前位置: 移动技术网 > 移动技术>移动开发>IOS > iPhone/iPad开发通过LocalNotification实现iOS定时本地推送功能

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

2019年07月24日  | 移动技术网移动技术  | 我要评论

通过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];
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网