iOS 容联离线消息推送
容联 SDK 是包含离线消息推送的。首先我们要在控制台上传P12证书,(生产证书和开发证书),(证书的配置这里就不多说了)只能有一个证书是生效中的
生产证书需要打包成 ipa 包才能测试离线推送
然后在看下代码中的配置
注册 APNS
/** 注册远程通知 */
- (void)registerRemoteNotification { if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Xcode 8编译会调用
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
if (!error) {
NSLog(@"request authorization succeeded!");
}
}]; [[UIApplication sharedApplication] registerForRemoteNotifications];
#else // Xcode 7编译会调用
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
#endif
} else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeBadge);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
}
}
#pragma mark - APP运行中接收到通知(推送)处理 /** APP已经接收到“远程”通知(推送) - (App运行在后台/App运行在前台) */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{ /////////下面是 IM
self.callid = nil;
NSString *userdata = [userInfo objectForKey:@"c"];
NSLog(@"远程推送userdata:%@",userdata);
if (userdata) {
NSDictionary*callidobj = [NSJSONSerialization JSONObjectWithData:[userdata dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"远程推送callidobj:%@",callidobj);
if ([callidobj isKindOfClass:[NSDictionary class]]) {
self.callid = [callidobj objectForKey:@"callid"];
}
} NSLog(@"远程推送 callid=%@",self.callid);
}
角标的显示
- (void)applicationWillResignActive:(UIApplication *)application { NSInteger count = ;
UINavigationController * rootView = (UINavigationController*)self.window.rootViewController;
if ([rootView.viewControllers[] isKindOfClass:[MainViewController class]]) {
count = [[IMMsgDBAccess sharedInstance] getUnreadMessageCountFromSession];
}
application.applicationIconBadgeNumber = count; //离线消息的角标数显示
[[ECDevice sharedInstance] setAppleBadgeNumber:count completion:^(ECError *error) { }];
usleep();
}
注意,在容联登录的地方要设置对应的环境.不设置默认代表是生产环境要对应生产环境的证书
-(void)resetResourceServer {
[self setAppKey:DefaultAppKey AndAppToken:DefaultAppToke];
//Caches文件路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//服务器配置文件夹
NSString * config = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"config.data"];
if ([[NSFileManager defaultManager] fileExistsAtPath:config]) {
[[NSFileManager defaultManager] removeItemAtPath:config error:nil];
}
#ifdef DEBUG
[[ECDevice sharedInstance] SwitchServerEvn:YES];
#else
[[ECDevice sharedInstance] SwitchServerEvn:NO];
#endif
}
iOS 容联离线消息推送的更多相关文章
- Push:iOS基于APNS的消息推送
1. Push的三个步骤,如下图所示: (1)Push服务应用程序把要发送的消息.目的iPhone的标识打包,发给APNS: (2)APNS在自身的已注册Push服务的iPhone列表中,查找有相应标 ...
- 使用PushSharp进行IOS发布应用的消息推送
在做.NET向IOS设备的App进行消息推送时候,采用的是PushSharp开源类库进行消息的推送,而在开发过程中,采用的是测试版本的app,使用的是测试的p12证书采用的是ApnsConfigura ...
- iOS开发如何实现消息推送机制
一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说来,当要显示消息 ...
- ios 消息推送流程 转载
iOS开发:推送通知简述及开发实践热度 1已有 706 次阅读 2013-10-15 09:23 |个人分类:经验之谈|系统分类:ios| IOS, 推送一.关于推送通知 推送通知,也被叫做远程通知, ...
- 基于APNs最新HTTP/2接口实现iOS的高性能消息推送(服务端篇)
1.前言 本文要分享的消息推送指的是当iOS端APP被关闭或者处于后台时,还能收到消息/信息/指令的能力. 这种在APP处于后台或关闭情况下的消息推送能力,通常在以下场景下非常有用: 1)IM即时通讯 ...
- iOS 之消息推送(个推)---个人小结
前言:自从上个星期开始整这个推送,弄了差不多一个星期,今天终于给整好了,因此现在来记录这段"奇妙"的旅程. 我们公司使用的消息推送是用的第三方--个推,这里不得不说一下,个推的技术 ...
- 了解iOS消息推送一文就够:史上最全iOS Push技术详解
本文作者:陈裕发, 腾讯系统测试工程师,由腾讯WeTest整理发表. 1.引言 开发iOS系统中的Push推送,通常有以下3种情况: 1)在线Push:比如QQ.微信等IM界面处于前台时,聊天消息和指 ...
- ios手机app消息推送
h5+app项目,推送平台 " 个推 " 首先在manifest.json配置文件中点击模块权限配置,勾选push消息推送配置如图1-1 第二部在manifest.json配置文件 ...
- 分分钟搞定IOS远程消息推送
一.引言 IOS中消息的推送有两种方式,分别是本地推送和远程推送,本地推送在http://my.oschina.net/u/2340880/blog/405491这篇博客中有详细的介绍,这里主要讨论远 ...
随机推荐
- 【LeetCode】282. Expression Add Operators
题目: Given a string that contains only digits 0-9 and a target value, return all possibilities to add ...
- 演讲:对 2000 多亿条数据做一次 group by 需要多久?
http://2017.qconbeijing.com/presentation/646?utm_source=weibo&utm_medium=infoq&utm_campaign= ...
- VS13+OPCV2.4.11
转载:http://blog.csdn.net/a934270082/article/details/50843266?locationNum=3&fps=1 1. 配置系统环境变量:计算机 ...
- matlab新手入门(四)(翻译)
工作空间变量 工作区包含您在数据文件或其他程序中创建或导入到MATLAB®中的变量. 例如,这些语句在工作空间中创建变量A和B. A=255; b=ones(size(Img)); 您可以使用whos ...
- update-alternatives --Install
up vote 1 down vote favorite I typed: sudo update-alternatives --install "/usr/bin/java" & ...
- java多线程系列:Executors框架
目录 Executor接口介绍 ExecutorService常用接口介绍 创建线程池的一些方法介绍 3.1 newFixedThreadPool方法 3.2 newCachedThreadPool方 ...
- Gym - 101889E Enigma(数位填数+记忆化)
https://cn.vjudge.net/problem/Gym-101889E 1??????????????????????????????? 2 10000000000000000000000 ...
- 求斐波那契数列第n位的几种实现方式及性能对比(c#语言)
在每一种编程语言里,斐波那契数列的计算方式都是一个经典的话题.它可能有很多种计算方式,例如:递归.迭代.数学公式.哪种算法最容易理解,哪种算法是性能最好的呢? 这里给大家分享一下我对它的研究和总结:下 ...
- poj3225(线段树区间更新&hash)
题目链接: http://poj.org/problem?id=3225 题意: 初始给一个全局为 0~65536 的区间 s, 然后不断地对区间 s 进行 并, 交, 差, 相对差等运算, 输出最 ...
- poj3164(最小树形图&朱刘算法模板)
题目链接:http://poj.org/problem?id=3164 题意:第一行为n, m,接下来n行为n个点的二维坐标, 再接下来m行每行输入两个数u, v,表点u到点v是单向可达的,求这个有向 ...