iOS极光推送(接收后台消息和自定义消息)
2016-07-29 18:40
585 查看
1.极光推送包括:APNs推送,JPush应用内消息。
JPush 代理开发者的应用(需要基于开发者提供的应用证书),向苹果 APNs 服务器推送。由 APNs Server 推送到 iOS 设备上。
JPush 应用内推送部分,即 App 启动时,内嵌的 JPush SDK 会开启长连接到 JPush Server,从而 JPush Server 可以推送消息到 App 里。
2.根据极光文档中JPush集成指南配置证书,导入框架,配置工程。
3.在appDelegate的didfinishlaunching方法里添加
JPush 代理开发者的应用(需要基于开发者提供的应用证书),向苹果 APNs 服务器推送。由 APNs Server 推送到 iOS 设备上。
JPush 应用内推送部分,即 App 启动时,内嵌的 JPush SDK 会开启长连接到 JPush Server,从而 JPush Server 可以推送消息到 App 里。
2.根据极光文档中JPush集成指南配置证书,导入框架,配置工程。
3.在appDelegate的didfinishlaunching方法里添加
//注册极光推送 [JPUSHService setupWithOption:nil appKey:@"" channel:nil apsForProduction:YES]; //获取自定义消息 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil]; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { //可以添加自定义categories [JPUSHService registerForRemoteNotificationTypes:( UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]; } else { //categories 必须为nil [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil]; } #pragma mark 获取自定义消息内容 - (void)networkDidReceiveMessage:(NSNotification *)notification { NSDictionary * userInfo = [notification userInfo]; NSString *content = [userInfo valueForKey:@"content"]; NSDictionary *extras = [userInfo valueForKey:@"extras"]; NSString *customizeField1 = [extras valueForKey:@"123456"]; //自定义参数,key是自己定义的 NSLog(@"自定义message:%@",userInfo); NSLog(@"推%@",content); NSLog(@"推%@",extras); NSLog(@"推%@",customizeField1); } #pragma mark 接收推送的消息 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"推送的消息:NSDictionary:%@",userInfo); [JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } #pragma mark 极光推送添加的内容 -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [JPUSHService registerDeviceToken:deviceToken]; } #pragma mark 失败回调方法 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); } #pragma mark 极光推送设置别名和标签,后台可以根据别名和签名给指定的用户发送消息 温馨提示:设置别名和签名时注意call back的处理结果,返回值为0才设置成功 if ([dic[@"weProtectUserType"] isEqualToString:@"administrator"]) { NSMutableSet *set = [[NSMutableSet alloc] initWithObjects:@"A", nil]; [JPUSHService setTags:set alias:alisa fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { NSLog(@"设置签名与别名1:%d",iResCode); NSLog(@"推送返回的%@%@",iTags,iAlias); } ]; }else { NSMutableSet *set = [[NSMutableSet alloc] initWithObjects:@"C", nil]; [JPUSHService setTags:set alias:alisa fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { NSLog(@"设置签名与别名2:%d",iResCode); NSLog(@"推送返回的%@%@",iTags,iAlias); } ]; }
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- Android ADT 23.0.0无法更新到23.0.2问题解决方案
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- SDKMAN:轻松管理多个软件开发套件 (SDK) 的命令行工具
- Parse正式发布开源PHP SDK
- 基于Android SDK-在64位Linux中使用需要注意的问题
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程