0

My app has a login page, people need to input a passcode,then they can login into inside. Everything of my app is work on my several iPhone before I submit it to iTuneConnect,then it has been approved by Apple. Something happened when I download it back from app store. Status of the HUD is always loading......It can not login into inside.

Here is my simple code:

@synthesize threadCount = _threadCount;


- (void) initData
{
    _codeIsVaild = NO; 
}


- (IBAction)Login:(id)sender
{
    _threadCount = 0;

    //Login procedure
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
        hud.labelText = @"Loading...";
        [hud showAnimated:YES whileExecutingBlock:^{

            [self getData];
            while (_threadCount != 5) {
                //Waiting for all tasks complete...It will be pass when the threads counter is equal 5
            }
        } completionBlock:^{

            if (_codeIsVaild)
            {
                //Password is Vaild
                [self performSegueWithIdentifier:@"loginsegue" sender:self];
            }
            else
            {
                //Show error Alert
            }
            [hud removeFromSuperview];
        }];
    }
}


-(void) getData
{

    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    NSString *URLString = [APILink getData];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    [manager POST:URLString parameters:paras
         success:^(AFHTTPRequestOperation *operation, id responseObject)
        {
            //Tasks
            [self taskone];
            [self tasktwo];
            [self taskthree];
            [self taskfour];
            [self taskfive];
            _codeIsVaild = YES;
        }
        else
        {
             _codeIsVaild = NO;
        }
            dispatch_semaphore_signal(semaphore);
        }
    failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        _codeIsVaild = NO;
        dispatch_semaphore_signal(semaphore);
    }];
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}


-(void) taskone
{
    NSString *URLString = [APILink taskoneAPIurl];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    [manager POST:URLString parameters:paras
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             _threadCount += 1;
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             _threadCount += 1;
         }];
}

//Same as taskone,but get data from another url
-(void) taskTwo
-(void) taskThree
-(void) taskFour
-(void) taskFive   

I think the problem is asynchronous tasks management. If that is the case, all of my phone should not be able to login.The strangest thing is that it works properly on my phone before I upload it to the app store, but it can not work properly when I download it from app store. What can I do? Thanks everyone.

Brian
  • 15,599
  • 4
  • 46
  • 63
  • Finally,I found a solution,refer to the URL: How to batch request with AFNetworking 2? This indicates that the code can not wait for the results of several requests, the use of an endless loop to wait. You should use dispatch_group_t & dispatch_group_notify Thanks CirrusFlyer & everyone! Have a good day! – user3789802 Jul 01 '14 at 07:38

2 Answers2

1

Finally,I found a solution,refer to the URL: How to batch request with AFNetworking 2?

This indicates that the code can not wait for the results of several requests, the use of an endless loop to wait.

You should use dispatch_group_t & dispatch_group_notify

Thanks CirrusFlyer & everyone!

Have a good day!

Community
  • 1
  • 1
0

I'd have to watch it through a debugger to offer any genuine help, but it sounds like you're not moving past either the getData() method or your while loop's stop condition is never met (my money is on the later as it doesn't appear you have a thread-safe variable to begin with ... a big no-no if your termination condition is based on it).

As a suggestion you might want to add some logging - something you can get to - to use for debugging purposes in addition to ensuring there are no race conditions.

BonanzaDriver
  • 6,411
  • 5
  • 32
  • 35
  • I can not use the debugger problem downloading it from the app store later, so that's what I ask​​. But before I submitted to iTunes connect, everything is ok, debugger displays the results were normal. – user3789802 Jul 01 '14 at 00:52