फेंकता मैं सच में यकीन है कि क्यों मेरे कोड एक EXC_BAD_ACCESS फेंक है नहीं कर रहा हूँ, मैं एप्पल के दस्तावेज में दिशा-निर्देशों का पालन किया है:अतुल्यकालिक NSURLConnection EXC_BAD_ACCESS
-(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!");
}
}
और मेरे प्रतिनिधि तरीकों
#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];
}
मैं didReceiveData पर एक EXC_BAD_ACCESS। भले ही उस विधि में एक एनएसएलॉग शामिल है, मुझे त्रुटि मिलती है।
नोट: receivedData आप इसे अंदर कोड की didRecieveData पर त्रुटि मिल रहे हैं, भले ही ऐसा लगता है कि आपका प्रतिनिधि की तरह मुक्त कर दिया कर दिया गया है मेरे हेडर फाइल
आपकी 'प्राप्त डेटा' चर शुरू करने वाली रेखा में 'डेटा' क्या है? – Mark