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

消息推送在现在的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];

}

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

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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值