Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9042009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:22:44+00:00 2026-06-16T10:22:44+00:00

I am making a project that uses the AFNetworking Library. I use it to

  • 0

I am making a project that uses the AFNetworking Library. I use it to check for a login and password with the webservice. This gives me a 200-code back if it is ok. If it is 200, I set a boolean to true so that the application can continue. But this boolean is not set at the right time. I always need to press two times on my login button before it works. Here is my code to set the boolean.

    - (BOOL)credentialsValidated {
    self.progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.progressHUD.labelText = @"Loading";
    self.progressHUD.mode = MBProgressHUDModeIndeterminate;
    self.progressHUD.dimBackground = YES;
     [[API sharedInstance] loginCommand:[NSMutableDictionary dictionaryWithObjectsAndKeys:_txtLogin.text,@"email",_txtPass.text,@"pwd", nil] onCompletion:^(NSDictionary *json){
     //completion
         if(![json objectForKey:@"error"]){
             NSLog(@"status %@",[json valueForKeyPath:@"data.status"]);
             if([[json valueForKeyPath:@"data.status"]intValue] == 200){
                //Create user object


                _loginstatus =  YES;
                [self.progressHUD hide:YES afterDelay:5];
             }else{
                 //show validation
                 _txtLogin.text = @"";
                 _txtPass.text = @"";
                 _loginstatus = NO;
             }
         }else {
             NSLog(@"Cannot connect to the server");
         }
     }];
     if(_loginstatus){
         NSLog(@"true");
    }else{
        NSLog(@"false");
    }
    [self.progressHUD hide:YES afterDelay:5];
     return _loginstatus;
}

And here is my API code.

-(void)loginCommand:(NSMutableDictionary *)params onCompletion:(JSONResponseBlock)completionBlock{
    NSLog(@"%@%@",kAPIHost,kAPILogin);
    NSMutableURLRequest *apiRequest = [self multipartFormRequestWithMethod:@"POST" path:kAPILogin parameters:params constructingBodyWithBlock:^(id <AFMultipartFormData>formData){
        //TODO: attach file if needed

    }];
    AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:apiRequest];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
        //success !
        NSLog(@"SUCCESSSS!");
        completionBlock(responseObject);
    }failure:^(AFHTTPRequestOperation *operation, NSError *error){
        //Failure
        NSLog(@"FAILUREE!");
        completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
    }];
    [operation start];

}

When I put below [operation start] the [operation waitUntilFinish] code, the app crashes.

Can somebody help me with this?

Kind regards

LOG
Here is a print of my log after I 2 two times pressed the login button

2012-12-28 09:36:00.547 Offitel[6532:907] http://virtuele-receptie.******.sanmax.be/nl/webservice/company-user/****/*****/**************
2012-12-28 09:36:00.561 Offitel[6532:907] false
2012-12-28 09:36:01.604 Offitel[6532:907] SUCCESSSS!
2012-12-28 09:36:01.605 Offitel[6532:907] status 200
2012-12-28 09:36:20.742 Offitel[6532:907] aanmelden pressed
2012-12-28 09:36:20.746 Offitel[6532:907] http://virtuele-receptie.******.sanmax.be/nl/webservice/company-user/****/*****/**************
2012-12-28 09:36:20.748 Offitel[6532:907] true
2012-12-28 09:36:22.184 Offitel[6532:907] SUCCESSSS!
2012-12-28 09:36:22.184 Offitel[6532:907] status 200
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:22:45+00:00Added an answer on June 16, 2026 at 10:22 am

    If you do this

    return _loginstatus;
    

    You are not waiting the operation to finish, so you’re not returning what your server is sending to your application. What I usually do in this cases is display an UIActivityIndicator when the login action is fired, and do nothing till’ the server has responded. Then, I set the proper values to any variables and in this case I would segue to home screen.

    Remember that when you’re using AFNetworking you are always doing async stuff.

    EDIT

    Code example:

    - (void)loginActionWithPassword:(NSString *)pass
    {
        // Add progress HUD to show feedback
        // I'm using MBProgressHUD library: https://github.com/jdg/MBProgressHUD#readme
        self.progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        self.progressHUD.labelText = @"Loading";
        self.progressHUD.mode = MBProgressHUDModeIndeterminate;
        self.progressHUD.dimBackground = YES;
    
        // Launch the action to the server
        [Actions loginWithEmail:[self.textEmail.text lowercaseString] andPassword:pass success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
            if ([Actions requestFailed:JSON]) {
                LOG(@"ERROR %@ / %@ / %@ \n", pass, request, response, JSON);
                if ([JSON[@"MSG"] isEqualToString:@"USER_NOT_REGISTERED"]) {
                    self.progressHUD.labelText = @"User doesn't exist";
                    self.textEmail.text = @"";
                    self.textPassword.text = @"";
                } else if ([JSON[@"MSG"] isEqualToString:@"PASSWORD_INCORRECT"]) {
                    self.progressHUD.labelText = @"Wrong password";
                    self.textPassword.text = @"";
                }
                [self.progressHUD hide:YES afterDelay:[Utils hudDuration]];
                return;
            }
            // If everything went OK, go to this function to save user data
            // and perform segue to home screen (or dismiss modal login view)
            [self onLoginSuccessWithPassword:pass JSON:JSON response:response];
        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
            // If something fails, display an error message
            LOG(@"ERROR:(%@): %@ / %@ / %@ / %@ \n", pass, request, response, error, JSON);
            self.progressHUD.labelText = @"Something went wrong, try again";
            [self.progressHUD hide:YES afterDelay:[Utils hudDuration]];
            return;
        }];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making extensive use of Markdown in a new project that I'm working on,
I have an AS3 project making use of compile time constants. This has worked
I'm making this little project with fwrite (long story, and I can't use DB's).
I am making a project that uses Autoconf. I have the following in configure.ac
I'm making a web based project management application using MySQL and PHP that uses
I have a Django project that uses SQLAlchemy to use some legacy ORM objects.
I am making a project that uses barcodes to store information relating to the
I am making a project that uses streamreader and streamwriter, Is it possible that
I'm making a new project that uses bower from twitter. I created a component.json
I am making a project that should compile on Windows and Linux. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.