經由過程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准時當地推送功效】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!