容联 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 容联离线消息推送的更多相关文章

  1. Push:iOS基于APNS的消息推送

    1. Push的三个步骤,如下图所示: (1)Push服务应用程序把要发送的消息.目的iPhone的标识打包,发给APNS: (2)APNS在自身的已注册Push服务的iPhone列表中,查找有相应标 ...

  2. 使用PushSharp进行IOS发布应用的消息推送

    在做.NET向IOS设备的App进行消息推送时候,采用的是PushSharp开源类库进行消息的推送,而在开发过程中,采用的是测试版本的app,使用的是测试的p12证书采用的是ApnsConfigura ...

  3. iOS开发如何实现消息推送机制

    一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说来,当要显示消息 ...

  4. ios 消息推送流程 转载

    iOS开发:推送通知简述及开发实践热度 1已有 706 次阅读 2013-10-15 09:23 |个人分类:经验之谈|系统分类:ios| IOS, 推送一.关于推送通知 推送通知,也被叫做远程通知, ...

  5. 基于APNs最新HTTP/2接口实现iOS的高性能消息推送(服务端篇)

    1.前言 本文要分享的消息推送指的是当iOS端APP被关闭或者处于后台时,还能收到消息/信息/指令的能力. 这种在APP处于后台或关闭情况下的消息推送能力,通常在以下场景下非常有用: 1)IM即时通讯 ...

  6. iOS 之消息推送(个推)---个人小结

    前言:自从上个星期开始整这个推送,弄了差不多一个星期,今天终于给整好了,因此现在来记录这段"奇妙"的旅程. 我们公司使用的消息推送是用的第三方--个推,这里不得不说一下,个推的技术 ...

  7. 了解iOS消息推送一文就够:史上最全iOS Push技术详解

    本文作者:陈裕发, 腾讯系统测试工程师,由腾讯WeTest整理发表. 1.引言 开发iOS系统中的Push推送,通常有以下3种情况: 1)在线Push:比如QQ.微信等IM界面处于前台时,聊天消息和指 ...

  8. ios手机app消息推送

    h5+app项目,推送平台 " 个推 " 首先在manifest.json配置文件中点击模块权限配置,勾选push消息推送配置如图1-1 第二部在manifest.json配置文件 ...

  9. 分分钟搞定IOS远程消息推送

    一.引言 IOS中消息的推送有两种方式,分别是本地推送和远程推送,本地推送在http://my.oschina.net/u/2340880/blog/405491这篇博客中有详细的介绍,这里主要讨论远 ...

随机推荐

  1. 「P4996」「洛谷11月月赛」 咕咕咕(数论

    题目描述 小 F 是一个能鸽善鹉的同学,他经常把事情拖到最后一天才去做,导致他的某些日子总是非常匆忙. 比如,时间回溯到了 2018 年 11 月 3 日.小 F 望着自己的任务清单: 看 iG 夺冠 ...

  2. bzoj 4516: 生成魔咒 后缀数组

    题目大意 在结尾动态插入字符,每次插入结束后输出当前串中本质不同的字串个数 题解 注意一开始是空串,然后我们我们可以打表观察规律 我们发现一直在开头插入字符和一直在结尾插入字符得到的答案是一样的 所以 ...

  3. opencv报错 error: (-215) size.width>0 && size.height>0 in function cv::imshow

    使用opencv读取摄像头并且显示事出现此问题: 后来发现是图像为空时的错误,加入: if(!frame.empty()) imshow("video",frame); 完整的代码 ...

  4. snmp++开发实例一

    1.官网下载 snmp开发,首先需要机器已经安装了snmp服务,这方面的资料网上比较完备,安装的时候注意每少一个文件,网上都可以下载到,这样可以自己形成一个包,供以后使用.只要最后snmp的服务开启就 ...

  5. Linux的学习思路

    自学嵌入式确实不大现实(当然也不是说没有这个可能),毕竟嵌入式难度也是比较大的. 嵌入式的应用主要是几个方向, 一是系统开发:侧重开发环境搭建.内核原理.交叉编译等: 二是嵌入式Linux应用开发:侧 ...

  6. IoT:template

    ylbtech-IoT: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtech.cnb ...

  7. js css3实现钟表效果

    原理: 利用transform-origin改变旋转的圆心,实现秒数和分钟数的刻度线,利用transfrom translate实现钟表小时刻度的显示 html: <div class=&quo ...

  8. java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter

    转自:https://blog.csdn.net/rchm8519/article/details/23788053 1. ERROR - Context initialization failedo ...

  9. Oracle查看表空间和表空间中的对象

    select * from user_tables;--查询所有用户表 select username,default_tablespace from user_users;--查询当前表空间sele ...

  10. AngularJs(Part 1)

    I am tired to translate these into Chinese. but who cares? i write these posts just for myself Scope ...