国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iPhone/iPad開發通過LocalNotification實現iOS定時本地推送功能

2019-10-21 18:52:19
字體:
來源:轉載
供稿:網友

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 焉耆| 文化| 江山市| 昭苏县| 曲麻莱县| 嘉祥县| 成武县| 南投市| 保靖县| 民县| 布拖县| 武义县| 涡阳县| 邮箱| 林西县| 托克托县| 句容市| 驻马店市| 平武县| 清徐县| 阿拉善盟| 许昌县| 绥化市| 宁河县| 格尔木市| 拜泉县| 耒阳市| 疏附县| 泰和县| 宜昌市| 新蔡县| 韩城市| 军事| 璧山县| 丰顺县| 枣阳市| 太白县| 宜川县| 蕲春县| 聊城市| 且末县|