关闭

ios app运行时提示推送

132人阅读 评论(0) 收藏 举报
分类:
在<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];
}




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:18272次
    • 积分:1027
    • 等级:
    • 排名:千里之外
    • 原创:83篇
    • 转载:24篇
    • 译文:0篇
    • 评论:4条
    文章分类