views:

319

answers:

1

Hi Friends,

I am doing my functionality in a secondary thread and once I get the result, I call the function that pops my ViewController in the main thread. But I get the following error:

void WebThreadLockFromAnyThread(), 0x5c6dec0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread..

I am using the code below:

-(IBAction)done{

if([self validateRegistrationDetails]){


        [NSThread detachNewThreadSelector:@selector(invokeWebService) toTarget:self withObject:nil];

}

}

-(void) invokeWebService{

NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];




NSString *url = [NSString stringWithFormat:@"%@%@action=1&userName=%@&eMail=%@&firstName=%@&lastName=%@&mobileNo=%@",kBaseURL,kRegisterFunction,userName.text,eMail.text,firstName.text,lastName.text,mobileNo.text];   

[ADCUtilities performSelectorOnMainThread:@selector(updateText:) withObject:@"Registering... "waitUntilDone:NO];

[ADCUtilities performSelectorOnMainThread:@selector(showIndicator:) withObject:self.view waitUntilDone:NO];

NSDictionary *tempDict = [webService makeAPICall:url];

    [NSThread sleepForTimeInterval:3];
if(tempDict!=nil){

NSString *tempLoginSuccess = [tempDict valueForKey:kLoginStatus] ;



if([tempLoginSuccess isEqual:@"LoginSuccess"]){


    [ADCUtilities displayAlertView:NSLocalizedString(@"REG_SUCCESS",@"")];

    [self performSelectorOnMainThread:@selector(popViewController) withObject:nil waitUntilDone:NO];


}
else{


    [ADCUtilities performSelectorOnMainThread:@selector( dismissIndicator) withObject:nil waitUntilDone:NO];

    [ADCUtilities displayAlertView:NSLocalizedString(@"REG_FAILED",@"")];

}
}
else {

    [ADCUtilities performSelectorOnMainThread:@selector( dismissIndicator) withObject:nil waitUntilDone:NO];

    [ADCUtilities displayAlertView:NSLocalizedString(@"REG_FAILED",@"")];

}

[pool release];

} -(void)popViewController{

[self.navigationController popViewControllerAnimated:YES];

}

Regards, krishnan.

+1  A: 

I think your problem is actually [ADCUtilities displayAlertView:NSLocalizedString(@"REG_SUCCESS",@"")], which I assume displays some sort of UIAlertView. You should never access any UIKit classes except from the main thread.

eman
Hi Eman,That was the problem. Thanks for the solution. Sorry I could not reply at the earliest.
Krishnan