iPhone/iPad開發(fā)通過LocalNotification實現(xiàn)iOS定時本地推送功能
通過iOS的UILocalNotification Class可以實現(xiàn)本地app的定時推送功能,即使當(dāng)前app是后臺關(guān)閉狀態(tài)。
可以實現(xiàn)諸如,設(shè)置app badgenum,彈出一個alert,播放聲音等等,實現(xiàn)很簡單
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就一目了然了,很方便,在適當(dāng)場合使用還是蠻實用的~
源代碼鏈接:https://github.com/andypan1314/LocalNotificationTest
iOS 設(shè)置每天下午4點推送本地通知
UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil) {//判斷系統(tǒng)是否支持本地通知
notification.fireDate = [NSDate dateWithTimeIntervalSince1970:16*60*60*24];//本次開啟立即執(zhí)行的周期
notification.repeatInterval=kCFCalendarUnitWeekday;//循環(huán)通知的周期
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.alertBody=@"哇哇哇";//彈出的提示信息
notification.applicationIconBadgeNumber=0; //應(yīng)用程序的右上角小數(shù)字
notification.soundName= UILocalNotificationDefaultSoundName;//本地化通知的聲音
//notification.alertAction = NSLocalizedString(@"美女呀", nil); //彈出的提示框按鈕
notification.hasAction = NO;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS 底部按鈕和應(yīng)用圖標(biāo)顯示未讀消息(帶數(shù)字)
本文主要介紹了iOS 底部按鈕和應(yīng)用圖標(biāo)顯示未讀消息的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04
iOS實現(xiàn)類似格瓦拉電影的轉(zhuǎn)場動畫
這篇文章主要給大家介紹了利用iOS如何實現(xiàn)類似格瓦拉電影的轉(zhuǎn)場動畫,文中給出了詳細(xì)步驟實現(xiàn)代碼,對大家的學(xué)習(xí)和理解很有幫助,有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-11-11
iOS實現(xiàn)自動循環(huán)播放的banner實例詳解
輪播視圖通常也叫Banner,90%以上App都會用到的一個控件,網(wǎng)上有很多開源代碼,下面這篇文章主要給大家介紹了關(guān)于利用iOS如何實現(xiàn)自動循環(huán)播放的banner的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。2017-12-12
Objective-C 代碼與Javascript 代碼相互調(diào)用實例
這篇文章主要介紹了Objective-C 代碼與Javascript 代碼相互調(diào)用實例的相關(guān)資料,現(xiàn)在的APP 應(yīng)用有時候會調(diào)用網(wǎng)頁上的內(nèi)容,為了增加用戶體驗,這里寫下個實例,需要的朋友可以參考下2016-10-10

