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

首頁 > 系統 > iOS > 正文

iOS客戶端本地推送實現代碼

2020-07-26 03:03:44
字體:
來源:轉載
供稿:網友

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

首先創建全局的本地通知對象及彈出框

// 彈出本地消息@property(nonatomic,strong)UILocalNotification *localNotification;@property(nonatomic,strong)UIAlertController *alertcontrol;其次在代碼中實現如下:- (void)application:(UIApplication *)applicationdidReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {  // 判斷程序是否在打開狀態,即是否在前臺運行的狀態  if (application.applicationState == UIApplicationStateActive) {    // 如果之前已經接受到消息,并且用戶未對彈出框進行處理,關閉原來彈出框    if (self.localNotification) {      [self.alertcontrol dismissViewControllerAnimated:YES completion:nil];    }    [self bulidLocationNotification:application userinfo:userInfo];          }else{    // 判斷程序是否未打開狀態,即是否在后臺運行或關閉狀態,極光推送設置角標    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];      }}// 創建本地推送消息-(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];}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三河市| 炎陵县| 江口县| 南靖县| 南昌市| 全椒县| 连城县| 西乡县| 肃北| 伊春市| 剑阁县| 龙井市| 花垣县| 陆川县| 临清市| 杭州市| 定远县| 长阳| 杭锦旗| 礼泉县| 青田县| 通辽市| 浠水县| 健康| 天门市| 潢川县| 宜州市| 西贡区| 塘沽区| 宽甸| 大同县| 银川市| 孟津县| 和田县| 桐柏县| 同仁县| 门源| 佛教| 铁力市| 峨边| 三原县|