ios app运行时提示推送

在<span style="font-family: Arial, Helvetica, sans-serif;">didReceiveRemoteNotification中添加(收到推送时调用)</span>
//app处于运行状态时
    if (application.applicationState == UIApplicationStateActive) {
        pushDic =[[NSDictionary alloc]initWithDictionary:userInfo];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"推送消息"
                                                            message:alert
                                                           delegate:self
                                                  cancelButtonTitle:@"我知道了"
                                                  otherButtonTitles:@"点击查看",nil];
        [alertView show];
    }
    else{
         [self goToMssageViewControllerWith:userInfo];
    }



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex ==1) {
        [self goToMssageViewControllerWith:pushDic];
    }
}

- (void)goToMssageViewControllerWith:(NSDictionary*)msgDic{
    //将字段存入本地,因为要在你要跳转的页面用它来判断,这里我只介绍跳转一个页面,
    NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];
    [pushJudge setObject:@"push"forKey:@"push"];
    [pushJudge synchronize];
    NSString * targetStr = [msgDic objectForKey:@"type"];
    if ([targetStr isEqualToString:@"7"]){ 
        QuanLiListViewController * VC = [[QuanLiListViewController alloc]init];
        UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:VC];//这里加导航栏是因为我跳转的页面带导航栏,如果跳转的页面不带导航,那这句话请省去。
        [self.window.rootViewController presentViewController:Nav animated:YES completion:nil];
    }
}


在跳转到的界面分别正常进入还是推送进入

NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    NSString *orPush = [NSString stringWithFormat:@"%@",[defaults objectForKey:@"push"]];
    if ([orPush isEqualToString:@"push"]) {
         self.navigationController.navigationBarHidden =YES;
         [leftbut addTarget:self action:@selector(rebackToRootViewAction) forControlEvents:UIControlEventTouchUpInside];
    }else{
         [leftbut addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    }

推送进入,退出后将推送进入的辨识去掉

- (void)rebackToRootViewAction
{
    NSUserDefaults * pushJudge = [NSUserDefaults standardUserDefaults];
    [pushJudge setObject:@""forKey:@"push"];
    [pushJudge synchronize];//记得立即同步
    [self dismissViewControllerAnimated:YES completion:nil];
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值