iOS通知消息的处理

废话不多说,直接正题!

对于通知消息的处理代理方法

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
     if(deviceToken) {

          if (![deviceToken isKindOfClass:[NSData class]])
              return;
          const unsigned *tokenBytes = [deviceToken bytes];
          NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                                ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                                ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                                ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

          [WPNotificationManager saveDeviceToken:hexToken];
      }
}

//收到远程推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    NSLog(@"noti:%@",notification);
    //应用处于后台时的本地推送接受

}
//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSDictionary * userInfo = notification.request.content.userInfo;
    
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //应用处于前台时的远程推送接受      
    }else{
        //应用处于前台时的本地推送接受
 
    }
 completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}

//iOS10新增:处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
    NSDictionary * userInfo = response.notification.request.content.userInfo;
  
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //应用处于后台时的远程推送接受 
        
    }else{
        //应用处于后台时的本地推送接受

    }
    
}

上篇:本地通知消息的发送

如有瑕疵之处,望大家不吝指教

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
    欧辰_OSR阅读 30,031评论 8 265
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,906评论 1 32
  • 准备早点睡的。结果接到了一个电话。 快一两年没联系过了。 裹件衣服蹲在楼梯口,叼跟烟暖暖。 她说她今晚看书的时候讲...
    王小贱的杂货铺阅读 3,933评论 0 1
  • 忘记了我的阿公是哪一年出生的了,我只听他说过,他比我阿婆要小上三岁,那个时候,流行的是“女大三抱金砖”的说法。我的...
    苏州郁阅读 4,377评论 0 7
  • 跟墨宝视频完,郭先生关上了灯,点燃了三根蜡烛,时光荏苒,匆然间就三十岁了。。。。。 早晨睡醒,照例翻看手机,看见了...
    梦回昔日阅读 1,522评论 0 0

友情链接更多精彩内容