最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2016年11月28日 17:30:27   作者:遛馬  
這篇文章主要介紹了iOS客戶端本地推送實(shí)現(xiàn)代碼,并確定程序中只有一個(gè)彈出框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

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

// 彈出本地消息
@property(nonatomic,strong)UILocalNotification *localNotification;
@property(nonatomic,strong)UIAlertController *alertcontrol;

其次在代碼中實(shí)現(xiàn)如下:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:
(void (^)(UIBackgroundFetchResult))completionHandler {
  // 判斷程序是否在打開狀態(tài),即是否在前臺(tái)運(yùn)行的狀態(tài)
  if (application.applicationState == UIApplicationStateActive) {
    // 如果之前已經(jīng)接受到消息,并且用戶未對(duì)彈出框進(jìn)行處理,關(guān)閉原來彈出框
    if (self.localNotification) {
      [self.alertcontrol dismissViewControllerAnimated:YES completion:nil];
    }
    [self bulidLocationNotification:application userinfo:userInfo];
    
    
  }else{
    // 判斷程序是否未打開狀態(tài),即是否在后臺(tái)運(yùn)行或關(guān)閉狀態(tài),極光推送設(shè)置角標(biāo)
    if ([application applicationIconBadgeNumber]>0) {
      [JPUSHService setBadge:[application applicationIconBadgeNumber]];
    }
  }
  
  [JPUSHService handleRemoteNotification:userInfo];
  NSLog(@"收到通知:%@", [self logDic:userInfo]);
  completionHandler(UIBackgroundFetchResultNewData);
}

- (void)application:(UIApplication *)application
didReceiveLocalNotification:(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

南阳市| 宁波市| 桦南县| 仲巴县| 仁寿县| 礼泉县| 哈尔滨市| 邳州市| 尼玛县| 宿迁市| 会东县| 鸡西市| 涡阳县| 涞源县| 巴彦县| 呼伦贝尔市| 夹江县| 柳江县| 周口市| 余姚市| 浠水县| 稷山县| 海原县| 甘泉县| 乐昌市| 临城县| 水城县| 洛南县| 鹿泉市| 安丘市| 礼泉县| 尚义县| 玉龙| 东方市| 张掖市| 蒙城县| 五大连池市| 巫山县| 株洲市| 普安县| 潮安县|