在<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];
}