我使用AFnetworking进行身份验证,但在验证用户后,我需要移动到下一个View控制器。它会移动,但也会在出现错误时移动。如何根据我的需要利用AFNetworking中的responseObject ......以下是我的CODE
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
//[operation setCredential:credential];
[operation setResponseSerializer:[AFJSONResponseSerializer alloc]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//This is where if the response is successful it should move
if ([responseObject objectForKey:@"Success"]) {
MainView *home = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[self.navigationController pushViewController:home animated:YES];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
}];
[manager.operationQueue addOperation:operation];
答案 0 :(得分:0)
要检查是否成功,您正在使用:
if ([responseObject objectForKey:@"Success"])
我不知道你的服务和检索Diccionary,但是我认为你总是有一个对象为@"成功",因为@"成功"存在正在传递所有场景。
尝试检查值,例如:
if ([[responseObject objectForKey:@"Success"] isEqualsToString @"ok"])