- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
} else {
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)
#else
categories:nil];
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)
#endif
categories:nil];
}
[APService setupWithOption:launchOptions];
if (launchOptions) {
NSDictionary * remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
//这个判断是在程序没有运行的情况下收到通知,点击通知跳转页面
if (remoteNotification) {
NSLog(@"推送消息==== %@",remoteNotification);
[self goToMssageViewControllerWith:remoteNotification];
}
}
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
[APService registerDeviceToken:deviceToken];
NSLog(@"%@", [NSString stringWithFormat:@"Device Token: %@", deviceToken]);
}

// 当 DeviceToken 获取失败时,系统会回调此方法

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"DeviceToken 获取失败,原因:%@",error);
}
  • 下面的这个方法也很重要,这里主要处理推送过来的消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"尼玛的推送消息呢===%@",userInfo);
// 取得 APNs 标准信息内容,如果没需要可以不取
NSDictionary *aps = [userInfo valueForKey:@"aps"];
NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
NSInteger badge = [[aps valueForKey:@"badge"] integerValue];
NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
// 取得自定义字段内容,userInfo就是后台返回的JSON数据,是一个字典
[APService handleRemoteNotification:userInfo];
application.applicationIconBadgeNumber = 0;
[self goToMssageViewControllerWith:userInfo];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
[application setApplicationIconBadgeNumber:0]; //清除角标
[application cancelAllLocalNotifications];
}
- (void)goToMssageViewControllerWith:(NSDictionary*)msgDic{
//将字段存入本地,因为要在你要跳转的页面用它来判断,这里我只介绍跳转一个页面,
NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];
[pushJudge setObject:@"push"forKey:@"push"];
[pushJudge synchronize];
NSString * targetStr = [msgDic objectForKey:@"target"];
if ([targetStr isEqualToString:@"notice"]) {
MessageVC * VC = [[MessageVC alloc]init];
UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:VC];//这里加导航栏是因为我跳转的页面带导航栏,如果跳转的页面不带导航,那这句话请省去。
[self.window.rootViewController presentViewController:Nav animated:YES completion:nil]; }
}
  • 下面介绍要跳转的页面MessageVC里面要做什么处理,其实里面的代码也很简单。看代码,在viewWillAppear里面自行创建一个返回按钮,根据在AppDelegate里面用NSUserDefaults保存的字段做判断。
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:YES];
[super viewWillAppear:YES];
NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];
if([[pushJudge objectForKey:@"push"]isEqualToString:@"push"]) {
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"02_03f@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rebackToRootViewAction)];
}else{
self.navigationItem.leftBarButtonItem=nil;
}
}
- (void)rebackToRootViewAction {
NSUserDefaults * pushJudge = [NSUserDefaults standardUserDefaults];
[pushJudge setObject:@""forKey:@"push"];
[pushJudge synchronize];//记得立即同步
[self dismissViewControllerAnimated:YES completion:nil];
}

这样就搞定了。 下面贴出后台返回的字段,我是根据这些地段判断跳转不同的页面。

屏幕快照 2015-11-24 下午8.50.02.png

下图是后台给的接口文档

屏幕快照 2015-11-24 下午9.35.55.png

上述代码可能会有点乱,如有疑问请留言
看了一下太代码太乱下面上截图

屏幕快照 2015-11-24 下午9.39.05.png

屏幕快照 2015-11-24 下午9.40.08.png

屏幕快照 2015-11-24 下午8.58.11.png

屏幕快照 2015-11-24 下午9.40.43.png

上面5个图里面的代码都在AppDelegate.m里面

下面一个图是在MessageVC里面,就是你要跳转的那个页面

屏幕快照 2015-11-24 下午9.42.27.png
 

iOS极光推送 点击推送消息跳转页面的更多相关文章

  1. iOS 极光推送 如何点击推送消息跳转页面

    假如你已经集成完了极光,恰好有这个问题不知如何解决,可以看看这篇文章,这篇是针对远程通知的,本地通知大同小异吧. 根据我项目的要求,极光推送跳转指定页面分为两种情况:app在后台情况和app在杀死的情 ...

  2. iOS 关于信鸽推送点击推送通知的处理

    最近的项目中使用了推送模块,使用的是企鹅帝国的信鸽推送服务,关于具体怎么推送的,证书如何设置,我不再赘述,一来开发文档中已经讲的非常清楚,二来在网上一搜的话也能搜到一大堆:在这里主要写下关于推送的通知 ...

  3. 点击button传递消息,但是页面不跳转的解决方法

    最近在做一个物联网的项目时遇到的问题:界面上有很多控制开/关灯的button,通过点击button来控制各个灯的亮灭.我需要将获取的不同的点击事件消息,以Socket通信的方式发送给硬件端的服务监听程 ...

  4. uniapp点击底部tabbar不跳转页面

    一个项目,其设想是这样的,当我进入页面,发现有新版本,提示用户之后,用户点击确定跳转到下载页面. 弹出框要用自己封装的,因为uniapp的弹出框不同的手机上展示的样子不一样,领导的是华为(在这里悄悄吐 ...

  5. android map高德地图显示多个点,并且每个marker点可以响应鼠标点击事件,处理跳转页面

    定义一个数组,然后将要显示的markers放进数组里面,让后循环每个marke对象,赋予监听事件,在监听事件里面写其它需要的功能: js举例: var arr = new Arry(); var ma ...

  6. UpdatePanel中点击按钮Session过期跳转页面相关问题:Sys.WebForms.PageRequestManagerParserErrorException:无法分析从服务器收到的消息

    使用 Response.Write("<script language=javascript>window.location.href='Login.aspx';</scr ...

  7. iOS点击推送消息跳到应用指定页面

    现在的推送用的越来越频繁,几乎每个应用都开始用到了.其实又有几个用户会去看推送消息呢?没办法,产品经理最大啊,只是苦了我们这一帮程序员啊!闲话少说,进入正题.兄弟我用的是极光推送,自然是以极光推送为例 ...

  8. iOS极光推送

    昨天花了一下午的时间研究了下极光推送,也前也是没做过,不知道从何下手!才开始的时候一看官方的SDK感觉好难,不过经过一系列的捣鼓之后,手机收到了推送信息,感觉其实并没有那么难! 1.配置开发证书(得有 ...

  9. iOS极光推送的基本使用

    昨天花了一下午的时间研究了下极光推送,也前也是没做过,不知道从何下手!才开始的时候一看官方的SDK感觉好难,不过经过一系列的捣鼓之后,手机收到了推送信息,感觉其实并没有那么难! 1.配置开发证书(得有 ...

随机推荐

  1. SqlHelper.cs

    public static class SqlHelper { public static object FromDbValue(object value) { if (value == DBNull ...

  2. CoreAnimation笔记

    核心动画继承结构 CoreAnimation Core Animation是直接作用在CALayer上的(并非UIView上)非常强大的跨Mac OS X和iOS平台的动画处理API,Core Ani ...

  3. MySQL 的乐观并发控制Optimistic concurrency control

    默认情况下, MySQL的Innodb事务隔离级别是重复读 repeatable read, SELECT @@GLOBAL.tx_isolation, @@tx_isolation;REPEATAB ...

  4. 探索Windows 8.1 Update 新功能点

    Windows 8.1 Update 已经使用一段时间了,整体感觉比Windows 8.1 方便了不少,尤其是对鼠标用户来说更是进行了很多优化. 应用磁贴尺寸 在应用磁贴点击鼠标右键,有小.中.宽.大 ...

  5. [转]源代码的管理和发布:以SVN为例

    FROM : http://ju.outofmemory.cn/entry/47277 前几天在微博吐槽了SVN的几个不爽的地方:.svn文件满天飞.分支管理的麻烦.不爽一般来说都是有过对比后才有如此 ...

  6. Linux时间函数之gettimeofday()函数之使用方法

    1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...

  7. 大数据下多流形聚类分析之谱聚类SC

    大数据,人人都说大数据:类似于人人都知道黄晓明跟AB结婚一样,那么什么是大数据?对不起,作为一个本科还没毕业的小白实在是无法回答这个问题.我只知道目前研究的是高维,分布在n远远大于2的欧式空间的数据如 ...

  8. MVC5 + EF6 + Bootstrap3 (15) 应用ModelState和Data Annotation做服务器端数据验证

    Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-server-side-validation.html 系列 ...

  9. WPF 小技巧

    在使用mvvm模式开发时,对于Command的绑定是一件很伤脑筋的事情,尽管有强大的Blend类库支持: xmlns:Custom="http://www.galasoft.ch/mvvml ...

  10. async 更优雅异步体验

    上一篇<让 Generator 自启动>介绍了通过起动器让 Generator 跑起来,而本篇采用 async 实现更优雅的异步编程. 从例子开始 借用上一篇例子中的例子说起. funct ...