Ios PushNotification重定向到受尊重的viewcontroller

Ios PushNotification重定向到受尊重的viewcontroller,ios,objective-c,iphone,ios8,Ios,Objective C,Iphone,Ios8,我正在应用程序中使用推送通知。我的问题是,如果用户收到应用程序外的推送通知,用户应该能够单击该通知横幅并 带到显示通知的“活动”页面 任何人都可以帮我解决这个问题。我是推送通知的新手。//在AppDelegate.m中使用此代码 -(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo { //code for navigate to viewc

我正在应用程序中使用推送通知。我的问题是,如果用户收到应用程序外的推送通知,用户应该能够单击该通知横幅并 带到显示通知的“活动”页面


任何人都可以帮我解决这个问题。我是推送通知的新手。

//在AppDelegate.m中使用此代码

-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
 {
          //code for navigate to viewcontroller
          ActivityViewController *objActivity = [[ActivityViewController alloc]    initWithNibName:@"ActivityViewController" bundle:nil];
    [self.navigationcontroller pushViewController: objActivity animated:YES];

   }

因此,当应用程序转到后台并收到通知时,将在appdelegate.m文件中调用的方法是

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    // Here present the class you want 
}
}


我已经完成了上述代码,但当应用程序处于后台时,如果用户点击横幅收到通知,则应重定向到活动页面

您需要在推送通知用户信息负载中包含信息。然后应用程序可以解析和检查,使用它来确定应用程序打开时要执行的操作。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{




 NSString *aPayload=[userInfo objectForKey:@"payload"];

NSDictionary *JSON =
[NSJSONSerialization JSONObjectWithData: [aPayload  dataUsingEncoding:NSUTF8StringEncoding]
                                options: NSJSONReadingMutableContainers
                                  error: NULL];

if ([[JSON objectForKey:@"activity"]isEqualToString:@"encore"]) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Piggyback"
                                                    message: [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]
                                                   delegate: nil
                                          cancelButtonTitle:@"DONE"
                                          otherButtonTitles: nil];
           self.likeBedge=self.likeBedge+1;
   [alert show];

   [[NSNotificationCenter defaultCenter] postNotificationName:@"likeComment" object:self userInfo:userInfo];
}


else if ([[JSON objectForKey:@"activity"]isEqualToString:@"like"]||[[JSON objectForKey:@"activity"]isEqualToString:@"comment"]){
    self.likeBedge=self.likeBedge+1;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"likeComment" object:self userInfo:userInfo];
}



else if ([[JSON objectForKey:@"activity"]isEqualToString:@"started playing"]){
    self.postBedge=self.postBedge+1;
    NSLog(@"%d",self.postBedge);
    [[NSNotificationCenter defaultCenter] postNotificationName:@"started playing" object:self userInfo:userInfo];
}



else if ([[JSON objectForKey:@"activity"]isEqualToString:@"stopped playing"]){
     [[NSNotificationCenter defaultCenter] postNotificationName:@"stopped playing" object:self userInfo:userInfo];
}



else if ([[JSON objectForKey:@"activity"]isEqualToString:@"@user play"]||[[JSON objectForKey:@"activity"]isEqualToString:@"@user comment"]){
     [[NSNotificationCenter defaultCenter] postNotificationName:@"likeComment" object:self userInfo:userInfo];
}


return;