首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >iOS开发中点击推送跳转到指定页面

iOS开发中点击推送跳转到指定页面

作者头像
用户1451823
发布2018-09-13 15:48:51
发布2018-09-13 15:48:51
4K1
举报
文章被收录于专栏:DannyHoo的专栏DannyHoo的专栏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1337818

消息推送在现在的App中很常见,但同一个App中推送的消息可能有多种类型,点击推送需要跳转到不同的指定页面。

做法:

我们在接收到推送的时候发送通知,每个页面都接收通知,如果有通知就在当前页面进行页面的跳转跳转到指定页面。

如果在每个页面中都添加接收通知的代码会很麻烦,我们可以将接收通知的代码添加到基类中,这样就简单、方便了许多。可有些项目中的代码中可能没有基类,就像我们公司中的这个项目,那也没问题,我们可以为视图控制器添加一个分类,将接收通知的代码添加到分类中,再在pch文件中导入此分类。

接收推送发送通知的代码:

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{

//关闭友盟自带的弹出框

    UMessage setAutoAlert:NO;

    UMessage didReceiveRemoteNotification:userInfo;

     [NSNotificationCenter defaultCenter postNotificationName:@"pushNoti" object:nil];

}

接收通知进行页面跳转的代码,此代码在视图控制器的分类中:

  • (void)load

{

Method m1;

Method m2;

// 运行时替换方法

    m1 = class_getInstanceMethod(self, @selector(statisticsViewWillAppear:));

    m2 = class_getInstanceMethod(self, @selector(viewWillAppear:));

method_exchangeImplementations(m1, m2);

    m1 = class_getInstanceMethod(self, @selector(statisticsViewWillDisappear:));

    m2 = class_getInstanceMethod(self, @selector(viewWillDisappear:));

method_exchangeImplementations(m1, m2);

}

  • (void) statisticsViewWillAppear:(BOOL)animated

{

    self statisticsViewWillAppear:animated;

    [MobClick beginLogPageView:NSStringFromClass(self class)];

    [NSNotificationCenter defaultCenter addObserver:self selector:@selector(push) name:@"pushNoti" object:nil];

}

-(void) statisticsViewWillDisappear:(BOOL)animated

{

    self statisticsViewWillDisappear:animated;

    [MobClick endLogPageView:NSStringFromClass(self class)];

    [NSNotificationCenter defaultCenter removeObserver:self name:@"pushNoti" object:nil];

}

  • (void)push{

NotificationVC * notiVC = [NotificationVC alloc init];

    notiVC.hidesBottomBarWhenPushed = YES;

    self.navigationController pushViewController:notiVC animated:YES;

}

该项目中之前的友盟统计就添加到了该分类中.

好了,本篇博客的主要内容就这些,谢谢阅读。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年11月24日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档