Asynchrone NSURLConnection Wirft EXC_BAD_ACCESS

Ich bin mir nicht wirklich sicher, warum mein code wirft eine EXC_BAD_ACCESS, ich habe die Richtlinien, die in der Apple-Dokumentation:

-(void)getMessages:(NSString*)stream{

    NSString* myURL = [NSString stringWithFormat:@"http://www.someurl.com"];

    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL]];

    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (theConnection) {
        receivedData = [[NSMutableData data] retain];
    } else {
        NSLog(@"Connection Failed!");
    }

}

Und meine Stellvertretung Methoden

#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    //This method is called when the server has determined that it
    //has enough information to create the NSURLResponse.

    //It can be called multiple times, for example in the case of a
    //redirect, so each time we reset the data.

    //receivedData is an instance variable declared elsewhere.
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //Append the new data to receivedData.
    //receivedData is an instance variable declared elsewhere.
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
    //release the connection, and the data object
    [connection release];
    //receivedData is declared as a method instance elsewhere
    [receivedData release];

    //inform the user
    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //do something with the data
    //receivedData is declared as a method instance elsewhere
    NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);

    //release the connection, and the data object
    [connection release];
    [receivedData release];
}

Bekomme ich eine EXC_BAD_ACCESS auf didReceiveData. Auch wenn diese Methode enthält einfach ein NSLog, bekomme ich die Fehlermeldung.

Hinweis: receivedData ist ein NSMutableData* in meiner header-Datei

Was ist "Daten" in der Zeile, die beginnt Ihre 'receivedData' variable?

InformationsquelleAutor Sheehan Alam | 2010-05-10

Schreibe einen Kommentar