Я новичок в цели и в остальном. Мой код работает без ошибок, но сервер не показывает ни одного сделанного почтового запроса. URL и имена методов верны, есть что-то еще, что я пропускаю?
ниже приведен код, который я использую
-(void)construct
{
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
URL = @"http://xx.xx.xx.xx:80/CW_war/getMyOffersCount";
}
- (void)run{
//mapping request object
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[CountResultVO class]];
[mapping mapKeyPath:@"offercount" toAttribute:@"offercount"];
[mapping mapKeyPath:@"insertCount" toAttribute:@"insertCount"];
[mapping mapKeyPath:@"favouriteOfferCount" toAttribute:@"favouriteOfferCount"];
[mapping mapKeyPath:@"favouriteInsertCount" toAttribute:@"favouriteInsertCount"];
//set mapping
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:mapping];forKeyPath:@"articles"];
//serializing post object
RKObjectMapping* outSerializationMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[outSerializationMapping mapAttributes:@"userId", @"userId", @"mode", @"mode", nil];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:outSerializationMapping forClass:[BasicUserArgVo class]];
//setting post params
RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:URL];
manager.acceptMIMEType = RKMIMETypeJSON;
manager.serializationMIMEType = RKMIMETypeJSON;
//setting post object router
[manager.router routeClass:[BasicUserArgVo class]
toResourcePath:@"/getMyOffersCount"
forMethod:RKRequestMethodPOST];
//init post object
BasicUserArgVo *bvo = [[BasicUserArgVo alloc]initWithUserId:5 andMode:nil];
//post object BasicUserArgVo and map to CountResultVO
[manager postObject:bvo mapResponseWith:mapping delegate:self];
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObject:(NSArray*)objects {
NSLog(@"hello");
CountResultVO* countResultVO = [objects objectAtIndex:0];
NSLog(@"RESULT : %ld %ld",[countResultVO offercount],[countResultVO insertCount]);
}
- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error {
NSLog([NSString stringWithFormat:@"Error: %@", [error localizedDescription]]);
}
=============================================================== *===== *
изменить:
objects-
@interface CountResultVO : NSObject
{
long offercount;
long insertCount;
long favouriteOfferCount;
long favouriteInsertCount;
}
@property(nonatomic,readwrite) long offercount;
@property(nonatomic,readwrite) long insertCount;
@property(nonatomic,readwrite) long favouriteOfferCount;
@property(nonatomic,readwrite) long favouriteInsertCount;
@end
и
@interface BasicUserArgVo : NSObject
{
long userId;
NSString *mode;
}
@property(nonatomic,readwrite) long userId;
@property(nonatomic,retain) NSString * mode;
-(id)initWithUserId:(long)uid andMode:(NSString *)m;
-(id)initWithUserId:(long)uid;
@end
, и я вызываю (void) метод run в моих приложениях viewDidLoad
- (void)viewDidLoad
{
RestKitUtil *restKitUtil = [[RestKitUtil alloc]init];
[restKitUtil run];
[super viewDidLoad];
}