1
現在我正在嘗試做一個帖子到我的/ api/v1 /登錄服務,然後當我得到響應返回到UserToken對象的映射。RestKit POST沒有將響應映射回對象
現在我已經工作了張貼用戶登陸數據下面的代碼,但它不是映射性反應回到對象:
- (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]
任何人都可以幫助我什麼我我在這裏失蹤?謝謝堆!