2014-10-06 66 views
1

我在我的應用程序中使用推送通知。我的問題是,如果用戶從應用程序中收到推送通知,用戶應該能夠單擊該通知橫幅並將其帶到顯示通知的活動頁面。PushNotification重定向到相關的視圖控制器

任何人都可以幫助我如何解決這個問題。我是推送通知中的新成員。在AppDelegate.m

+0

您需要在推送通知用戶信息有效內容中包含信息。該應用程序可以解析和檢查,使用它來確定應用程序打開時要執行的操作。 – CW0007007 2014-10-06 10:41:36

回答

1

//使用這個代碼

-(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]; 

    } 
0

所以當應用程序被切換到後臺,並在收到通知您將要在appdelegate.m文件調用的方法是

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    // Here present the class you want 
} 
1
- (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; 

}

我已經這樣做了上面的代碼,但是當應用程序在後臺,如果沒有tification是用戶點擊橫幅它應該重定向到活動頁面

相關問題