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,查看模板详情 根据模板 ...
随机推荐
- 从零开始学android开发-通过WebService进行网络编程,使用工具类轻松实现
相信大家在平常的开发中,对网络的操作用到HTTP协议比较多,通过我们使用Get或者Post的方法调用一个数据接口,然后服务器给我们返回JSON格式的数据,我们解析JSON数据然后展现给用户,相信很多人 ...
- C#中使用GUID的笔记
GUID(全局统一标识符)是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成GUID的API.生成算法很有意思,用到了以太网卡地址.纳秒级时间.芯片ID码和许多可 ...
- Cocos2d-x多语言支持解决方式
很多其它相关内容请查看本人博客:http://www.bokeyi.com/ll/category/cocos2d-x/ 利用.plist文件让Cocos2d-x轻松支持多语言. .plist文件类似 ...
- [Angular-Scaled Web] 8. Using $http to load JSON data
Using the $http service to make requests to remote servers. categories-model.js: angular.module('egg ...
- js判断图片是否显示
function getDefaultImg() { //添加判断图片是否存在操作 var $defaultImgPathObj = $('input[name=defaultImgPath]'); ...
- 已知json类型根据类型封装集合
1编写帮助类根绝url得到json public static string Post(string url) { string strURL = url; //创建一个HTTP请求 HttpWebR ...
- PHP下获取上个月、下个月、本月的日期(strtotime,date)
今天写程序的时候,突然发现了很早以前写的获取月份天数的函数,经典的switch版,但是获得上月天数的时候,我只是把月份-1了,估计当时太困了吧,再看到有种毛骨悚然的感觉,本来是想再处理一下的,但是一想 ...
- 115 Java Interview Questions and Answers – The ULTIMATE List--reference
In this tutorial we will discuss about different types of questions that can be used in a Java inter ...
- HBase Error: connection object not serializable
HBase Error: connection object not serializable 想在spark driver程序中连接HBase数据库,并将数据插入到HBase,但是在spark集群提 ...
- 模式匹配运算符–Shell
转载:http://www.firefoxbug.net/?p=722 Var=/home/firefox/MyProgram/fire.login.name ${Variable#patte ...