iOS 点击远程通知消息,跳转到指定页面 (控制器)

可能大家对跳转到任意控制器的理解有点不同。我自己的做法是通过通知来进行跳转的。appdelegate代理中接收到消息,将userInfo消息通过通知传出去,再此期间,需将跳转的控制器获取出来,接着其实就是获取你点击的某个控件比如cell的id传到那个控制器。然后在该控制器接收通知   

就我自己的项目来说:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    if (application.applicationState == UIApplicationStateActive) {
        NSLog(@"active");
        //程序当前正处于前台
        [application setApplicationIconBadgeNumber:0];
        
        NSString *messageAlert = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"远程通知" message:messageAlert delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"前往", nil];
        alertView.delegate = self;
        [alertView show];
        // 8秒后将退出弹框
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(8.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [alertView dismissWithClickedButtonIndex:0 animated:YES];

        });
    }
else if(application.applicationState == UIApplicationStateInactive)
    {
        NSLog(@"inactive");
        //程序处于后台
       // 发送通知到需要跳转的控制器中
        [[NSNotificationCenter defaultCenter]postNotificationName:@"123456" object:nil userInfo:userInfo];
        
    }
    // IOS 7 Support Required
    [APService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}


在你首页控制器的注册通知,并且跳转到每个要进入的页面
- (void)viewdidload
{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushNotification:) name:@"123456" object:nil];
    
}
- (void)pushNotification:(NSNotification *)notification
{
    NSDictionary *dict = notification.userInfo;
    
    // kpiid  其实就是后台传出来需要点击cell的id
    GTLog(@"===notification===%@",[dict valueForKey:@"kpiid"]);
    
    [self selectKPIModuleId:[[dict valueForKey:@"kpiid"] integerValue]];
}

/************************************************
*
*
*  点击相对应的kpiid模块,跳转到相对应的kpi控制器
*
*
************************************************/
- (void)selectKPIModuleId:(int)kpiid     // 此处是tableview  didselect方法中单独提取的方法
{
    
    //销售利润
    if(kpiid==1){
        ProfitViewController *pyc=[[ProfitViewController alloc] initWithNibName:@"ProfitViewController" bundle:nil];
        [(UINavigationController *)self.mm_drawerController.centerViewController pushViewController:pyc animated:YES];
        [[TimeTool sharedTimeTool] timeToolBTypeOfStartWhenIntoViewCurrentModuleID:1];
        return;
    }
    
大致的跳转就是这样的   所以说开发中没有变态不变态的需求  ,既然别人能想出来,必然可以去实现。so,有些事需要自己多想。后面有实现流程图,可以看一下


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值