I am trying to get data from response.
I'm using NSURLConnectionDelegate
, NSURLConnectionDataDelegate
.
The project uses ARC.
@interface MainMenu()
@property (nonatomic, unsafe_unretained) NSMutableData* wpData;
@end
@implementation
-(void)sendRequest{
NSURL* url = [[NSURL alloc] initWithString:@"http://smthing"];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
NSString* reqBody = @"Block";
NSData* reqData = [reqBody dataUsingEncoding:NSUTF8StringEncoding];
[request setURL:url];
[request setHTTPBody:reqData];
[request setHTTPMethod:@"POST"];
self.wpData = [NSMutableData data];
NSURLConnection* conection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conection start];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//Here iI have [__NSMallocBlock__ appendData:]: unrecognized selector sent to instance 0x95f3fb0
[self.wpData setLength:0];
}
@end
Maybe you can found my mistake
Thanks :)
Your data pointer is an unsafe_unretained
property,
@property (nonatomic, unsafe_unretained) NSMutableData* wpData;
and you are assigning it a autoreleased instance,
self.wpData = [NSMutableData data]; //Returns autoreleased object
Since you are making asynchronous download request you require to maintain the data object.
You never know when the autorelease pool will be flushed and the unretained object will go out of scope. In such situations you should retain
the autoreleased object. Change the property to strong
and allocate the data object,
@property (nonatomic, strong) NSMutableData* wpData;
//...
self.wpData = [[NSMutableData alloc] init]; //Better practice
Hope that helps!