iOS开发——消息推送跳转
项目开发用集成是极光推送JPush
这里主要是消息推送过来处理对应界面跳转
同时看到两篇写的不错的相关博客分享一下:
http://www.jianshu.com/p/eaf07c4372a8
http://www.jianshu.com/p/d4460fed39c1
推送的是根据用户ID及用户的绑定的JPush注册ID,对应用户推送。
首先看一下推送过来的消息格式:
推送来的字典:{
"_j_msgid" = 976126105;
aps = {
alert =
"\U865a\U62df\U7b56\U7565I160704711100001\U5356\U51fa\U80a1\U7968:\U5b9c\U534e\U5065\U5eb7100\U80a1\U3001\U4ef7\U683c\U4e3a32.15\U3001\U5171\U8ba13215\U2026\U2026";
badge = 50;
sound = "";
};
"pro_id" = 160704711100001;
"pro_type" = 1;
"type_id" = 1;
}
其中 "pro_id" = 160704711100001;
"pro_type" = 1;
"type_id" = 1;
这三个是后台服务自定义的键值信息,根据自己开发的需要自定义。主要靠这三个信息跳转到对应的界面。
而
alert =
"\U865a\U62df\U7b56\U7565I160704711100001\U5356\U51fa\U80a1\U7968:\U5b9c\U534e\U5065\U5eb7100\U80a1\U3001\U4ef7\U683c\U4e3a32.15\U3001\U5171\U8ba13215\U2026\U2026";
badge = 50;
sound = "";
这三个是推送的固定格式,不管谁的推送都有,alert是通知栏提示的消息信息,badge是桌面app数字角标提醒
sound是收到消息提醒的声音。
接收到推送的通知有三种情况,第一种,App未启动 第二种,App在前台 第三种,App在后台
第一种,App未启动的
时候,点击通知栏消息时,app从- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 这个方法里接受处理消息
处理逻辑为:将消息放到专门的方法dealRemoteNotification里处理分析后跳转
// 未启动 推送消息
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo){
[self dealRemoteNotification:userInfo];
}
其他的两种情况在下面方法处理
-
(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void
(^)(UIBackgroundFetchResult))completionHandler {
// iOS 7 Support Required
[self dealRemoteNotification:userInfo];
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
处理跳转的方法如下
// 推送消息处理跳转
-(void)dealRemoteNotification:(NSDictionary*)userInfo{ NSLog(@"推送来的字典:%@",userInfo);
// 取得 APNs 标准信息内容
// NSDictionary *aps = [userInfo valueForKey:@"aps"];
// NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
// NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
// NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
// // 前台的时候不处理消息跳转
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { // 前台不处理推送
return;
}
//服务端自定义键值
NSString *typeID = [userInfo valueForKey:@"type_id"]; // 真实虚拟
NSString *proType = [userInfo valueForKey:@"pro_type"]; // IMP还是ISM
NSString *proID = [userInfo valueForKey:@"pro_id"]; // id或code if (proType.integerValue == ){ // 消息助手详情 MsgAssistant_PushViewController *MsgVC = [[MsgAssistant_PushViewController alloc]init]; [self.window.rootViewController presentViewController:MsgVC animated:YES completion:^{ }]; } if (typeID.integerValue == ) { // 虚拟
if (proType.integerValue == ) { // ISM ISM_PushTradeCommandViewController *ISMPush = [[ISM_PushTradeCommandViewController alloc]init];
ISMPush.ismCodeString = proID;
ISMPush.isVirtualExperience = YES; [self.window.rootViewController presentViewController:ISMPush animated:YES completion:^{ }]; }else if(proType.integerValue == ){ // IMP // IMP交易记录
IMP_PushTradeRecordViewController *IMPPushVC = [[IMP_PushTradeRecordViewController alloc] init]; IMPPushVC.impId = proID;
IMPPushVC.isVirtualExperience = YES; [self.window.rootViewController presentViewController:IMPPushVC animated:YES completion:^{ }]; }else{
return ;
} }else if (typeID.integerValue == ){ // 真实 if (proType.integerValue == ) { // ISM ISM_PushTradeCommandViewController *ISMPush = [[ISM_PushTradeCommandViewController alloc]init];
ISMPush.ismCodeString = proID;
ISMPush.isVirtualExperience = NO; [self.window.rootViewController presentViewController:ISMPush animated:YES completion:^{ }]; }else if(proType.integerValue == ){ // IMP // IMP交易记录
IMP_PushTradeRecordViewController *IMPPushVC = [[IMP_PushTradeRecordViewController alloc] init]; IMPPushVC.impId = proID;
IMPPushVC.isVirtualExperience = NO; [self.window.rootViewController presentViewController:IMPPushVC animated:YES completion:^{ }]; }else{ return ;
} } }
本跳转是单个界面,没有下一级,所以没用导航控制器
根据个人情况处理,这里前台的时候没有处理,有的前台处理的时候是弹窗提示,引导跳转
同时注意 跳转的界面返回的处理,这里重写跳转界面返回事件
- (void)backButtonEvent{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
一般情况下,看完一个消息详情界面用户会点击返回退出此界面,
如果用户未退出消息详情界面,而下拉通知栏点击了消息,可能会由于未dimiss的界面,
新的消息详情界面无法present出来,建议处理消息的方法里跳转前发送通知到控制器执行dimiss操作。
iOS开发——消息推送跳转的更多相关文章
- iOS开发消息推送原理
转载自:http://www.cnblogs.com/cdts_change/p/3240893.html 一.消息推送原理: 在实现消息推送之前先提及几个于推送相关概念,如下图1-1: 1.Prov ...
- 玩转iOS开发 - 消息推送
消息推送
- iOS 10 消息推送(UserNotifications)秘籍总结(二)
背景 上一篇博客iOS 10 消息推送(UserNotifications)秘籍总结(一)发布后被 简书编辑推荐至首页,这着实让我受宠若惊啊.可是好事不长,后面发生了让我伤心欲绝的事,我的女朋友不要我 ...
- iOS开发 iOS10推送必看
iOS10更新之后,推送也是做了一些小小的修改,下面我就给大家仔细说说.希望看完我的这篇文章,对大家有所帮助. 一.简单入门篇---看完就可以简单适配完了 相对简单的推送证书以及环境的问题,我就不在这 ...
- iOS 远程消息推送,原理和开发详解篇(新手推荐)
1.APNS的推送机制 首先我们看一下苹果官方给出的对ios推送机制的解释.如下图 Provider就是我们自己程序的后台服务器,APNS是Apple Push Notification Servic ...
- iOS 之消息推送(个推)---个人小结
前言:自从上个星期开始整这个推送,弄了差不多一个星期,今天终于给整好了,因此现在来记录这段"奇妙"的旅程. 我们公司使用的消息推送是用的第三方--个推,这里不得不说一下,个推的技术 ...
- 分分钟搞定IOS远程消息推送
一.引言 IOS中消息的推送有两种方式,分别是本地推送和远程推送,本地推送在http://my.oschina.net/u/2340880/blog/405491这篇博客中有详细的介绍,这里主要讨论远 ...
- iOS 10 消息推送(UserNotifications)秘籍总结(一)
前言 之前说会单独整理消息通知的内容,但是因为工(就)作(是)的(很)事(懒)没有更新文章,违背了自己的学习的初衷.因为互联网一定要有危机意识,说不定眼一睁,我们就out丢了饭碗. 图片来源网络.jp ...
- PHP 微信公众号开发 - 消息推送
项目微信公众号开发,需要做用户消息推送,记录下来以便日后使用 1,接上一篇文章,可以查看如何获取用户openid PHP 微信公众号开发 - 获取用户信息 2,添加模板消息 3,查看模板详情 根据模板 ...
随机推荐
- Linux下安装、启动MySQL
启动与停止 1.启动 MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可. [root@localhost mysql]# /etc/init.d/my ...
- java中匿名类的讲解
匿名内部类也就是没有名字的内部类 正因为没有名字,所以匿名内部类只能使用一次,它通常用来简化代码编写 但使用匿名内部类还有个前提条件:必须继承一个父类或实现一个接口 实例1:不使用匿名内部类来实现抽象 ...
- 【转】The Zen of Python
http://www.python.org/dev/peps/pep-0020/ Beautiful is better than ugly. Explicit is better than impl ...
- 使用Filter防止浏览器缓存页面或请求结果
仅仅须要两步: 1.定义一个Filter: /** * 防止浏览器缓存页面或请求结果 * @author XuJijun * */ public class NoCacheFilter impleme ...
- 【转】Delphi调用webservice总结
原文:http://www.cnblogs.com/zhangzhifeng/archive/2013/08/15/3259084.html Delphi调用C#写的webservice 用delph ...
- 手机NFC通信的安全车钥匙
SmartKeys for Cyber-Cars:Secure Smartphone-based NFC-enabled Car Immobicizer 手机NFC通信的安全车钥匙 1概述 如今,智能 ...
- 《Linux内核设计与实现》读书笔记
http://www.cnblogs.com/wang_yb/tag/linux-kernel/
- 1083. List Grades (25)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1083 and the ...
- php编程中容易忽略的地方
一:fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] ...
- 琐碎-同步centos集群的时间
想马上上手HBase,其对集群时间同步要求很高,当然,hadoop也是