Go through the crash report....
This GDB was configured as "x86_64-apple-darwin".Attaching to process 1798.
2012-05-17 13:19:59.628 PDFView[1798:11603] bool _WebTryThreadLock(bool), 0x684b940: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 WebThreadLock
[Switching to process 1798 thread 0x11603]
2 -[UIWebView _webViewCommonInit:]
3 -[UIWebView initWithCoder:]
4 _decodeObjectBinary
5 _decodeObject
6 -[UIRuntimeConnection initWithCoder:]
7 _decodeObjectBinary
8 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
9 -[NSArray(NSArray) initWithCoder:]
10 _decodeObjectBinary
11 _decodeObject
12 -[UINib instantiateWithOwner:options:]
13 -[UIViewController _loadViewFromNibNamed:bundle:]
14 -[UIViewController loadView]
15 -[UIViewController view]
16 -[UIViewController viewControllerForRotation]
17 -[UIViewController _visibleView]
18 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
19 -[UIViewController presentViewController:withTransition:completion:]
20 -[UIViewController presentViewController:animated:completion:]
21 -[UIViewController presentModalViewController:animated:]
22 -[LoginPageVC loadVC]
23 __invoking___
24 -[NSInvocation invoke]
25 -[NSInvocationOperation main]
26 -[__NSOperationInternal start]
27 -[NSOperation start]
28 [Switching to process 1798 thread 0x11603]
__block_global_6
29 _dispatch_call_block_and_release
30 _dispatch_worker_thread2
31 _pthread_wqthread
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
I think that I am getting this error, its due to webview loading request on the other thread instead of main thread. I want to load the web view in the background to avoid UI blocking.
// calling other view controller
{
ViewController* objVC=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
NSString* PDFURLString = @"http://images.apple.com/xserve/pdf/L422277A_Xserve_Guide.pdf";
//creating diff thread.....
NSOperationQueue *queue = [NSOperationQueue new];
// create own NSInvocation Operation to call other function of other view controller class
NSInvocationOperation * operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadURL) object:PDFURLString];
// add operation to queue
[queue addOperation:operation];
[operation release];
[self presentModalViewController:objVC animated:YES];
}
// this the function called by ObjVC.
-(void)loadURl:(NSString*)urlString
{
[_indicator startAnimating];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:_PDFURLString]];
NSLog(@"loading URL DATA");
//Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
_filePath = [resourceDocPath stringByAppendingPathComponent:@"myPDF.pdf"];
NSLog(@"File Path:%@",_filePath);
[pdfData writeToFile:_filePath atomically:YES];
//Now create Request for the file that was saved in your documents folder
NSURL *url = [NSURL fileURLWithPath:_filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView setUserInteractionEnabled:YES];
_webView.scalesPageToFit = YES;
[_webView setDelegate:self];
[_webView loadRequest:requestObj];
}
Please look into my code and suggest the best method to load the web view on different thread, with UI responding meanwhile. Thanks.