更新时间:
2016年11月17日极光sdk提供的推送包括远程推送和长连接推送:
远程推送指服务器将要发给iphone的消息交给极光sdk来处理,极光sdk会负责管理设备token、向apns发送数据。使用该模式要求开发人员提供推送证书。长连接推送指服务器将要发给iphone的消息交给极光sdk来处理,极光sdk通过与iphone设备的长连接进行数据的传输,此过程不经过apns。
极光sdk使用的意义:
主要是使后台开发任务变的更加轻松。ios消息推送适配(极光sdk):
详细内容查看极光官网,一下介绍两个主要方面如果支持7-9
推送注册if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {//IOS8
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
消息获取和处理
只需要在如下方法中对消息进行处理
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS(7_0);
如果支持7-10
推送注册if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
} else if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {//IOS8
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
消息获取和处理
在实现1)的基础上实现ios10的消息处理,在如下方法中对消息进行处理[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]
或者使用极光sdk提供的对应方法对消息内容进行处理
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler;