質問

I am using AFnetworking for authentication, but after Authenticating user I need to move to the next View controller. It's moving, but also it moves when there's an error too. How can I make use of the responseObject in AFNetworking to my need...... Below is my 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];
役に立ちましたか?

解決

To check if success or not, you are using :

if ([responseObject objectForKey:@"Success"])

I don't know your service and the retrieve Diccionary, however I think you always have an object for the key @"Success", and because @"Success" exists is passing in all the scenarios.

Try to check the value, e.g.:

if ([[responseObject objectForKey:@"Success"] isEqualsToString @"ok"])
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top