views:

123

answers:

1

Hi!

I got this weird problem in implanting simple NSURLConnection...

The method didReceiveData get call and I'm happily trying to append the receive data but... nada!

There's some data for sure (as the length indicate but appendData do NOT append the data!

I start to bang my head on this one and I need some help before it's to late :-)

Here some code to look at :

My header...

@interface ActionViewController : UITableViewController {
 Site *site;

 NSURLConnection *siteConnection;
 NSMutableData *receivedData;
    UIView *waitView;
    UIActivityIndicatorView *activityIndicator;

 int nConnections;
    BOOL fail;
}

My implementation..

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    // Append the new data to receivedData.
 NSLog(@"Received %d bytes of data",[data length]);
    [receivedData appendData:data];
 NSLog(@"Received %d bytes of data",[receivedData length]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);

 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 [activityIndicator stopAnimating];
 waitView.hidden = YES;

    // release the connection
    [connection release];
}

The console output...

[Session started at 2010-08-21 21:27:55 -0400.]
2010-08-21 21:28:19.263 myApp[2042:207] Received 108 bytes of data
2010-08-21 21:28:19.263 myApp[2042:207] Received 0 bytes of data
2010-08-21 21:28:19.263 myApp[2042:207] Succeeded! Received 0 bytes of data

I don't get it! HELP!!!

BTW, the data is a simple xml result that look like this...

<donnee>0</donnee><donnee>0</donnee><donnee>0</donnee><donnee>1</donnee><donnee>0</donnee><donnee>0</donnee>
A: 

Well, got my answer in an another question on this site about NSMutableData... forgot to initialize the thing! (code 18 or a remainder of sending message to nil is a NICE feature of Objective-C)

receivedData = [[NSMutableData alloc] init];
Steve S.