现在我要做的是在我的/ api / v1 / login服务上发帖子,然后当我把响应地图发送到UserToken对象时。
现在我有以下代码用于发布UserLogin数据,但它没有将响应映射回对象:
- (void) postLogin
{
//Setup Login data
UserLogin *l = [[UserLogin alloc] initWithUsername:[usernameField text] andPassword:[passwordField text]];
//Setup Routes
RKObjectRouter *router = [RKObjectManager sharedManager].router;
[router routeClass:[UserLogin class] toResourcePath:@"/api/v1/login" forMethod:RKRequestMethodPOST];
//Setup Token Mapping
RKObjectMapping *UserTokenMapping = [RKObjectMapping mappingForClass:[UserToken class]];
[UserTokenMapping mapKeyPath:@"authentication_token" toAttribute:@"token"];
//[[[RKObjectManager sharedManager] mappingProvider]setMapping:UserTokenMapping forKeyPath:@""];
[[RKObjectManager sharedManager].mappingProvider registerMapping:UserTokenMapping withRootKeyPath:@""];
//Setup Mapping for UserLogin class
RKObjectMapping *UserLoginMapping = [RKObjectMapping mappingForClass:[UserLogin class]];
[UserLoginMapping mapKeyPath:@"login" toAttribute:@"userName"];
[UserLoginMapping mapKeyPath:@"password" toAttribute:@"passWord"];
[[RKObjectManager sharedManager].mappingProvider registerMapping:UserLoginMapping withRootKeyPath:@""];
[[RKObjectManager sharedManager] postObject:l delegate:self];
}
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
NSLog(@"objects[%d]", [objects count]);
}
回应如下:
{"message":"Login successful.","authentication_token":"2cksmLGr9hB5kLF3eRTu"}
objectLoader方法刚刚返回:
2012-09-26 23:49:57.046 voxpop_iphone[92118:c07] objects[0]
任何人都可以帮助我解决我在这里失踪的问题吗?谢谢堆!
答案 0 :(得分:0)
我遇到了同样的问题,并使用弃用的方法来调整正确的映射
相反
[[RKObjectManager sharedManager] postObject:l delegate:self];
我用过
[objectManager postObject:self mapResponseWith:UserTokenMapping delegate:self];