コードを実行すると、コードがスタックし、次のようなログが表示されます。
void _WebThreadLockFromAnyThread(bool), 0x904db10: メイン スレッドまたは Web スレッド以外のスレッドから Web ロックを取得しています。UIKit はセカンダリ スレッドから呼び出されるべきではありません。
その理由と解決策は何ですか?
私のコード:
-(IBAction)action:(id)sender{
NSLog(@"HI");
[self performSelectorInBackground:@selector(parse) withObject:nil];
}
-(void)parse{
rssOutputData = [[NSMutableArray alloc]init];
//[self performSelectorOnMainThread:@selector() withObject:nil waitUntilDone:NO];
[NSThread detachNewThreadSelector: @selector(startIndicator) toTarget: self withObject: self];
url=[[NSURL alloc]initWithString:[NSString stringWithFormat:@"http://service.technologyorg.com/service1/AuthenticateStudent=%@,%@,1",t1.text,t2.text]];
NSLog(@"A%@",url);
NSURLRequest *lRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
NSURLResponse *response;
NSError * error;
//[NSURLConnection connectionWithRequest:lRequest delegate:self];
[NSURLConnection sendSynchronousRequest:lRequest returningResponse:&response error:&error];
NSLog(@"AB%@",response);
if (nil == response) {
NSLog(@"%@",error);
[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"Connection failed!" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
xmlData=[[NSMutableData alloc]initWithContentsOfURL:url];
NSLog(@"B%@",xmlData);
xmltitle=nil;
xmlParserObject =[[NSXMLParser alloc]initWithData:xmlData];
[xmlParserObject setDelegate:self];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[xmlParserObject parse];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"XML:%@",xmllink);
if ([xmltitle isEqualToString:@"true"]) {
HomeViewController *lv=[[HomeViewController alloc]init];
lv.s1=[[NSString alloc]initWithFormat:@"%@",xmllink];
lv.s2=[[NSString alloc]initWithFormat:@"%@",xm1];
myStaticPassword=[[NSString alloc]initWithFormat:@"%@",xm2];
[self presentModalViewController:lv animated: YES];
[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
}else{
[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"Incorrect Username/Password" message:@"Please check your Username or Password" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[alert show];
}
});
});
}