容联 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. mysql的itcast笔记

    1 课程回顾 自定义标签&编码实战 1)自定义标签步骤: 1.1 编写标签处理器类,继承SimpleTagSupport类,覆盖doTag方法 1.2 在WEB-INF目录下建立tld文件,在 ...

  2. MVC之Control中使用AOP

    原文转载自http://www.cnblogs.com/iamlilinfeng/archive/2013/03/02/2940162.html 本文目标 一.能够使用Control中的AOP实现非业 ...

  3. 03_通过OpenHelper获取SqliteDatabase对象

    MyOpenHelper openHelper = new MyOpenHelper(this); 类似于java的File file = new File();只是声明这个东西,但是文件还并没有真正 ...

  4. PCL类的设计结构

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=243 类和应用程序接口 对于PCL的大多数类而言,调用接口(所有public ...

  5. There is no resul…

    There is no result type defined for type 'json' mapped with name 'success'. 这个错误是json初学者很容易遇到的错误:现在把 ...

  6. C# 写 LeetCode easy #13 Roman to Integer

    13.Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D and  ...

  7. 《剑指offer》面试题22—栈的压入、弹出序列

    <程序员面试宝典>上也有经典的火车进站问题,类似. 如果12345是压栈顺序,序列45321可能是出栈顺序,但序列43512不可能. 规律:对序列中任意元素n,排在n后且比n小的元素一定是 ...

  8. poj3667(线段树区间合并&区间查询)

    题目链接: http://poj.org/problem?id=3667 题意:第一行输入 n, m表示有 n 间房间(连成一排的), 接下来有 m 行输入, 对于接下来的 m 行输入: 1 x : ...

  9. Tyvj P1520 树的直径

    P1520 树的直径 http://www.tyvj.cn/p/1520 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 树的直径,即这棵树中距离最远的两个结 ...

  10. bzoj4889: [Tjoi2017]不勤劳的图书管理员(树套树)

    传送门 据说正解线段树套平衡树 然而网上参考(抄)了一个树状数组套动态开点线段树的 思路比较清楚,看代码应该就明白了 //minamoto #include<iostream> #incl ...