Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning a background thread not working
    primarykey
    data
    text
    <p>I'm trying to run -getHTMLupdate in background but it's not working.</p> <p>-viewDidLoad</p> <pre><code>- (void)viewDidLoad { UIImage *navBarImage = [[UIImage imageNamed:@"menubar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 15, 5, 15)];//Navbar [[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; [self performSelectorInBackground:@selector(getHTMLupdate) withObject:nil]; } </code></pre> <p>Here's -getHTMLupdate</p> <pre><code>-(void) getHTMLupdate { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; /* set headers, etc. on request if needed */ [request setURL:[NSURL URLWithString:@"http://appstarme.com/GD/GDHTMLPARSINGINFORMATION.php"]]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSScanner *scanner = [NSScanner scannerWithString:html]; NSString *token = nil; [scanner scanUpToString:@"&lt;h1&gt;" intoString:NULL]; [scanner scanUpToString:@"&lt;/h1&gt;" intoString:&amp;token]; NSLog(@"DATA : %@", html); _updateFromUser.text = html; </code></pre> <p>Here's the console output</p> <pre><code> 2013-07-02 20:26:25.775 Social App[8130:3707] DATA : Please check out the new Skype contest at www.Skype.com 2013-07-02 20:26:25.776 Social App[8130:3707] bool _WebTryThreadLock(bool), 0x1e8ab970: 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 0x3a021259 WebThreadLock 2 0x36083185 &lt;redacted&gt; 3 0xc75fd -[homeChannel getHTMLupdate] 4 0x349e7231 &lt;redacted&gt; 5 0x3c2170e1 &lt;redacted&gt; 6 0x3c216fa8 thread_start </code></pre> <p>The NSLog oddly returns the correct data but the app still crashes</p> <p>EDIT</p> <p>Added this at the end of the code</p> <pre><code>[_updateFromUser performSelectorOnMainThread: @selector(setText:) withObject: html waitUntilDone: FALSE]; </code></pre> <p>worked perfectly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload