所以在我的项目中使用“AFNetworking”时,我尝试了一些非常基本的例子,以确保它正常工作,但我不断收到以下错误:
[NSConcreteMutableData appendData:]: message sent to deallocated instance 0x83aa8030
我的代码是:
NSDictionary *params = @{@"username": username,
@"password": password,
@"comment_id": comment_id]};
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[manager POST:url parameters:params progress:nil success:^(NSURLSessionTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionTask * _Nullable operation, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];
错误发生在以下函数中,该函数是脚本的一部分:([AFURLSessionManagerTaskDelegate URLSession:dataTask:didReceiveData:] AFURLSessionManager.m:262)
#pragma mark - NSURLSessionDataDelegate
- (void)URLSession:(__unused NSURLSession *)session
dataTask:(__unused NSURLSessionDataTask *)dataTask
didReceiveData:(NSData *)data{
self.downloadProgress.totalUnitCount = dataTask.countOfBytesExpectedToReceive;
self.downloadProgress.completedUnitCount = dataTask.countOfBytesReceived;
[self.mutableData appendData:data];}
答案 0 :(得分:0)
尝试将AFHTTPSessionManager
的实例存储在您的类中作为属性。类似的东西:
@property (nonatomic, strong) AFHTTPSessionManager *manager;
然后你不应该看到关于解除分配对象的错误,希望如此! 否则请在问题上发布更多背景信息,以便我可以帮助您。