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.