1、

#pragma mark - 远程推送注册获得device Token
if (IOS_VERSION >= 10.0) { UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
[center setDelegate:self];
UNAuthorizationOptions type = UNAuthorizationOptionBadge | UNAuthorizationOptionSound |UNAuthorizationOptionAlert; [center requestAuthorizationWithOptions:type completionHandler:^(BOOL granted, NSError * _Nullable error) { if (granted) {
NSLog(@"注册成功");
}else{
NSLog(@"注册失败");
} }]; }else if (IOS_VERSION >= 8.0){ UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound |
UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes
categories:nil];
[application registerUserNotificationSettings:settings]; }else{
//ios8以下不适配了
}
// 注册获得device Token
[application registerForRemoteNotifications];

2、

#pragma mark - 远程推送注册获得device Token
// 将得到的deviceToken传给SDK
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *deviceTokenStr = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""]; NSLog(@"deviceTokenStr:\n%@",deviceTokenStr);
} // 注册deviceToken失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"注册deviceToken失败error -- %@",error);
}

3、

#pragma mark - 远程推送消息的处理 - iOS10以后
//在前台
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以设置
completionHandler(UNNotificationPresentationOptionBadge |
UNNotificationPresentationOptionSound |
UNNotificationPresentationOptionAlert); } //在后台、关闭状态
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
//处理推送过来的数据
NSLog(@"%@", response.notification.request.content.userInfo);
completionHandler();
} #pragma mark - 远程推送消息的处理 - iOS10之前
//在前台、在后台、关闭状态统一进入该方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary * _Nonnull)userInfo fetchCompletionHandler:(void (^ _Nonnull)(UIBackgroundFetchResult))completionHandler{ /*
UIApplicationStateActive 应用程序处于前台
UIApplicationStateBackground 应用程序在后台,用户从通知中心点击消息将程序从后台调至前台
UIApplicationStateInactive 用用程序处于关闭状态(不在前台也不在后台),用户通过点击通知中心的消息将客户端从关闭状态调至前台
*/ //应用程序在前台给一个提示特别消息
if (application.applicationState == UIApplicationStateActive) { //应用程序在前台
NSLog(@"应用程序在前台%@", userInfo); }else{ //其他两种情况,一种在后台程序没有被杀死,另一种是在程序已经杀死。用户点击推送的消息进入app的情况处理。
NSLog(@"应用程序在后台、关闭状态%@", userInfo); } completionHandler(UIBackgroundFetchResultNewData); }

APNs推送的系统做法的更多相关文章

  1. APNs 推送原理及问题

    http://bbs.csdn.net/topics/390461996 在 iOS 平台上,大部分应用是不允许在后台运行并连接网络的.在应用没有被运行的时候,只能通过 Apple Push Noti ...

  2. 手把手教你配置苹果APNS推送服务|钿畑的博客 | 钿畑的博客

    http://www.360doc.com/content/15/0118/17/1073512_441822850.shtml# 钿畑的文章索引 1. 什么是推送通知 2. 什么是APNS? 3. ...

  3. APNS推送原理详解

    推送是解决轮询所造成的流量消耗和电量消耗的一个比较好的解决方案,在Android上,虽然Google提供了GCM(之前为C2DM),但在国内基本等于没用,各大Android应用基本都自己架设推送Ser ...

  4. iOS开发之功能模块--Apns推送中的的json格式介绍

    在开发向苹果Apns推送消息服务功能,我们需要根据Apns接受的数据格式进行推送.下面接受我在进行apns推送时候总结的一点apns服务接受的Json数据格式 示例 1: 以下负载包含哦一个简单的 a ...

  5. Apns推送中的的json格式介绍

    在开发向苹果Apns推送消息服务功能,我们需要根据Apns接受的数据格式进行推送.下面接受我在进行apns推送时候总结的一点apns服务接受的Json数据格式 示例 1: 以下负载包含哦一个简单的 a ...

  6. iOS 后台调用apns推送

    1.java调用apns推送 2.php 调用apns 推送,可借助终端

  7. iOS apns推送

    前言:推送分为本地推送以及远程推送. 两者的区别为本地推送一般为定时推送.定期推送或者位置推送.而远程推送更为多样化,能满足较高的要求.当然远程推送需要服务器端开发,开发流程较复杂. 1.本地推送只需 ...

  8. python3 三行代码基于HTTP2完美实现APNS推送【详解】

    第一次做苹果APNS(Apple Push Notification service)推送,关于APNS推送原理以及证书的获取方式网上已经有许多资料,在此不做过多赘述,需要注意的是证书分为测试证书和正 ...

  9. iOS 下APNS推送处理函数具体解释

    相比起Android,iOS在推送方面无疑惯例得更好.APNS(Apple Push Notification Service)是苹果公司提供的消息推送服务.其原理就是.第三方应用将要推送给用户的信息 ...

随机推荐

  1. Bug搬运工-CSCvm33229:Environment summary not available on COS APs

    还是关于温度的问题, Environment summary not available on COS APs CSCvm33229   Description Symptom:From WLC CL ...

  2. 虚拟机中安装centos7后无法上网,使用桥接网络+ssh

    首先是桥接网络解决无法上网的问题: 1保证你Vmware里面的虚拟机是关机状态2右键点击电脑屏幕右下角小电脑图标,选择打开网络与共享中心,然后点击弹出来的窗口左上角的“更改适配器设置”.这里指的是你W ...

  3. 转:建立maven私服

    一.下载安装与配置 下载 到官网下载:https://www.sonatype.com/download-oss-sonatype   image.png 下载的是oss3.x版本的(当时最新版), ...

  4. [LeetCode] 735. Asteroid Collision

    行星碰撞. 题意是给一个数组 asteroids,表示在同一行的行星.对于数组中的每一个元素,其绝对值表示行星的大小,正负表示行星的移动方向(正表示向右移动,负表示向左移动).每一颗行星以相同的速度移 ...

  5. java实现文字转语音功能(仅Windows)

    一.pom.xml引入jar包依赖 <!-- https://mvnrepository.com/artifact/com.jacob/jacob 文字转语音 --> <depend ...

  6. 关于java继承条件下的构造方法调用

    首先是测试代码: class Grandparent { public Grandparent() { System.out.println("GrandParent Created.&qu ...

  7. 【PAT甲级】1054 The Dominant Color (20 分)

    题意: 输入两个正整数M和N(M<=800,N<=600),分别代表一张图片的宽度和高度,接着输入N行每行包括M个点的颜色编号,输出这张图片主导色的编号.(一张图片的主导色占据了一半以上的 ...

  8. 九、web.xml理解

    1.web.xml文件在每个web工程不是必须要有的:     web.xml文件是用来初始化配置信息:比如Welcome页面.servlet.servlet-mapping.filter.liste ...

  9. video标签 在微信浏览器打开,不弹出大的独立窗口 而是直接播放。

    1.在 video 标签中添加   属性    x5-playsinline  playsinline  webkit-playsinline="true" 2.ckplayer的 ...

  10. 刷题62. Unique Paths

    一.题目说明 题目62. Unique Paths,在一个m*n矩阵中,求从左上角Start到右下角Finish所有路径.其中每次只能向下.向右移动.难度是Medium! 二.我的解答 这个题目读读题 ...