Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's wrong on following URLConnection?
    text
    copied!<h3>See also:</h3> <blockquote> <p><a href="https://stackoverflow.com/questions/704985/objective-c-asynchronous-web-request-with-cookies">Objective-C Asynchronous Web Request with Cookies</a></p> </blockquote> <p>I spent a day writing this code and can anyone tell me what is wrong here?</p> <p>WSHelper is inherited from NSObject, I even tried NSDocument and NSObjectController and everything..</p> <pre><code>-(void) loadUrl: (NSString*) urlStr{ url = [[NSURL alloc] initWithString:urlStr]; request = [NSURLRequest requestWithURL:url cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 60.0]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; if(connection) { receivedData = [[NSMutableData data] retain]; //[connection start]; } else { display error etc... } NSApplication * app = [NSApplication sharedApplication]; [app runModalForWindow: waitWindow];// &lt;-- this is the problem... } -(void)connection: (NSURLConnection*)connection didReceiveData:(NSData*)data{ progressText = @"Receiving Data..."; [receivedData appendData:data]; } -(void)connection: (NSURLConnection *)connection didFailWithError:(NSError *)error{ progressText = @"Error..."; NSAlert * alert = [[NSAlert alloc] init]; [alert setMessageText:[error localizedDescription]]; [alert runModal]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ progressText = @"Done..."; pData = [[NSData alloc] initWithData:receivedData]; [self hideWindow]; } </code></pre> <p>The code just wont do anything, it doesnt progress at all. I even tried it with/without startImmediately:YES but no luck !!!, this is executed in main window so even the thread and its run loop is running successfully.</p> <p>I tried calling synchronous request, and it is working correctly !! But I need async solution.</p> <p>I have added CoreServices.Framework in project, is there anything more I should be adding to the project? any compiler settings? Or do i have to initialize anything before I can use NSURLConnection?</p> <p>Any solution to run NSURLConnection on different thread on its own NSRunLoop, Objective-C and MAC Development has no sample code anywhere in documentation that makes everything so difficult to code.</p>
 

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