这篇文章主要介绍了iPhone/iPad开发之通过LocalNotification实现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];
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:iPhone/iPad开发通过LocalNotification实现iOS定时本地推送功能
基础教程推荐
猜你喜欢
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Android中的webview监听每次URL变化实例 2023-01-23
- Flutter手势密码的实现示例(附demo) 2023-04-11
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Android多返回栈技术 2023-04-15
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- android studio按钮监听的5种方法实例详解 2023-01-12
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
