我正在尝试发布一个带有块的对象。OnDidFailWithError
从来没有被叫过,它爆炸了。
这是我得到的错误:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'+ [MyClass objectLoader:didFailWithError:]:无法识别的选择器发送到类
这是我的代码:
[[RKObjectManager sharedManager] postObject: myObj usingBlock:^(RKObjectLoader *loader){
loader.targetObject = nil;
loader.delegate = (id)self;
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[MyClass class]];
loader.onDidFailWithError = ^(NSError *error) {
NSLog(@"Error %@", [error localizedDescription]);
};
loader.onDidLoadObject = ^(id obj) {
NSLog(@"Comment");
NSLog(@"%@",obj);
};
loader.onDidLoadResponse = ^(RKResponse *response) {
NSLog(@"Response: %@", [response bodyAsString]);
};
loader.onDidLoadObjects=^(NSArray* objects){
//post notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"finish" object:nil];
};
loader.serializationMIMEType = RKMIMETypeJSON; // We want to send this request as JSON
loader.method = RKRequestMethodPOST;
loader.serializationMapping = [RKObjectMapping serializationMappingUsingBlock:^(RKObjectMapping* mapping) {
[mapping mapAttributes:@"field1", @"field2",nil];
}];
}];