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

首頁 > 系統(tǒng) > iOS > 正文

iOS客戶端本地推送實現(xiàn)代碼

2019-10-21 18:50:13
字體:
來源:轉載
供稿:網(wǎng)友

本文實例為大家分享了iOS本地推送的具體代碼,供大家參考,具體內(nèi)容如下

首先創(chuàng)建全局的本地通知對象及彈出框

// 彈出本地消息@property(nonatomic,strong)UILocalNotification *localNotification;@property(nonatomic,strong)UIAlertController *alertcontrol;其次在代碼中實現(xiàn)如下:- (void)application:(UIApplication *)applicationdidReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {  // 判斷程序是否在打開狀態(tài),即是否在前臺運行的狀態(tài)  if (application.applicationState == UIApplicationStateActive) {    // 如果之前已經(jīng)接受到消息,并且用戶未對彈出框進行處理,關閉原來彈出框    if (self.localNotification) {      [self.alertcontrol dismissViewControllerAnimated:YES completion:nil];    }    [self bulidLocationNotification:application userinfo:userInfo];          }else{    // 判斷程序是否未打開狀態(tài),即是否在后臺運行或關閉狀態(tài),極光推送設置角標    if ([application applicationIconBadgeNumber]>0) {      [JPUSHService setBadge:[application applicationIconBadgeNumber]];    }  }    [JPUSHService handleRemoteNotification:userInfo];  NSLog(@"收到通知:%@", [self logDic:userInfo]);  completionHandler(UIBackgroundFetchResultNewData);}- (void)application:(UIApplication *)applicationdidReceiveLocalNotification:(UILocalNotification *)notification {  // 彈出消息  if (self.localNotification) {    self.alertcontrol = [UIAlertController alertControllerWithTitle:@"" message:self.localNotification.alertBody preferredStyle:UIAlertControllerStyleAlert];    UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {      self.localNotification = nil;      self.alertcontrol = nil;    }];    [self.alertcontrol addAction:action];    [self.window.rootViewController presentViewController:self.alertcontrol animated:YES completion:nil];      }}// 創(chuàng)建本地推送消息-(void)bulidLocationNotification:(UIApplication *)application userinfo:(NSDictionary *)userInfo{  self.localNotification = [[UILocalNotification alloc]init];  self.localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];  self.localNotification.alertBody = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];  self.localNotification.alertAction = @"確定";  self.localNotification.soundName = @"sound.caf";  self.localNotification.userInfo = userInfo;  [application presentLocalNotificationNow:self.localNotification];}

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


注:相關教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 迭部县| 宝兴县| 桓仁| 吕梁市| 甘南县| 饶阳县| 绥滨县| 凤翔县| 施秉县| 西林县| 建阳市| 枣阳市| 洮南市| 普格县| 浦东新区| 奉贤区| 天柱县| SHOW| 闽清县| 沁阳市| 伊宁县| 竹北市| 黄大仙区| 玉溪市| 松溪县| 乌鲁木齐市| 峨眉山市| 眉山市| 浦江县| 宣化县| 斗六市| 乳山市| 历史| 合水县| 玛纳斯县| 瑞金市| 天峻县| 称多县| 修水县| 四川省| 鞍山市|