Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection doen't return data where dataWithContentsOfURL does
    primarykey
    data
    text
    <p>I have an application and I used to get my json data with <code>dataWithContentsOfURL</code>.<Br> But because I need to get it an asynchrone fashion.<br> Now that I use <code>NSURLConnection</code> to handle this I don't receive any useful data all I get is statuscode 200 in the <code>didReceiveResponse</code> method but <code>didReceiveData</code> is never called. And at <code>connectionDidFinishDownloading</code> <code>destinationURL</code> returns <code>null</code>.</p> <p>I have no idea wat couses this problem and I would really appreciate some help.</p> <p>the delegate</p> <pre><code>#import "NetWorkToGuiDelegate.h" @implementation NetWorkToGuiDelegate @synthesize data; @synthesize caller; - (id) init: (SEL) pointer :(NSObject *) c; { doWhenDone = pointer; self.caller = c; data = [[NSMutableData alloc]init]; return self; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSString *responseText = [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]; NSLog(@"%@",responseText); } - (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL { NSLog(@"post download finished"); data = [NSData dataWithContentsOfURL:destinationURL]; NSLog(@"data: %@",data); NSLog(@"URLconnection %@", connection.currentRequest); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [caller performSelector:doWhenDone withObject:data]; #pragma clang diagnostic pop } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [self.data setLength:0]; NSHTTPURLResponse *resp= (NSHTTPURLResponsae *) response; NSLog(@"got responce with status %d",[resp statusCode]); } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d { NSLog(@"data recieved %@",d); [self.data appendData:d]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"") message:[error localizedDescription] delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil] show]; NSLog(@"failed"); } // Handle basic authentication challenge if needed - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSString *username = @"username"; NSString *password = @"password"; NSURLCredential *credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; } @end </code></pre> <p>the call</p> <pre><code>NetWorkToGuiDelegate *nwgd = [[NetWorkToGuiDelegate alloc] init:@selector(login:) :self]; NSString *stringURL = [NSString stringWithFormat:@"%@%@%@%@", dk.baseURL, @"menu?code=",dk.loginCode,@"&amp;v=1"]; NSURL *url = [NSURL URLWithString:stringURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:nwgd]; [urlConnection start]; </code></pre> <p>I'll just add that the call happens on the main thread</p>
    singulars
    1. This table or related slice is empty.
    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.
    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