推送通知通过点击通知IOS7查看特定视图控制器

时间:2014-03-15 11:36:01

标签: ios iphone notifications

您好我的应用程序我有推送通知当用户点击通知它进入主视图控制器我通过点击通知我已经尝试了一些方法查看特定视图控制器它不适合我,所以请告诉我完成它。

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    const char* data = [deviceToken bytes];
    NSMutableString * token = [NSMutableString string];

    for (int i = 0; i < [deviceToken length]; i++) {
        [token appendFormat:@"%02.2hhX", data[i]];
    }

    NSString *urlString = [NSString stringWithFormat:@"url?token=%@",token];

    NSURL *url = [[NSURL alloc] initWithString:urlString];
    NSLog(@"token %@",urlString);


    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    NSLog(@"request %@ ",urlRequest);
    NSData *urlData;
    NSURLResponse *response;
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
    NSLog(@"data %@",urlData);
    [self clearNotifications];

}


-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    [[UIApplication sharedApplication] cancelLocalNotification:notification];

    //My_specificViewController
    updatepoliticalViewController *ringingVC = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"updatepoliticalViewController"];
    [self.window setRootViewController:ringingVC];
}

上面我已经尝试过它不起作用请告诉我在做什么是正确的方法来完成它。

感谢。

1 个答案:

答案 0 :(得分:0)

试试这个

不要设置为rootviewcontroller

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

     updatepoliticalViewController *ringingVC = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"updatepoliticalViewController"];
     [self.navigationController pushViewController:ringingVC animated:YES];
}