2014-06-16 1 views
0

J'essaye de mapper des attributs à une classe dans RESTKit sans un KVC imbriqué et sans beaucoup de chance je continue d'obtenir zéro pour mes valeurs même si la réponse contient des valeurs.Réponse de mappage de POST sans KVC imbriqué

J'ai lu le manuel de mappage d'objets et l'ai essayé avec des motifs de chemin sans motif de chemin, etc. Quelqu'un a-t-il un aperçu?

Demande et réponse du serveur

2014-06-16 15:58:07.162 game[5961:60b] T 

restkit.network:RKObjectRequestOperation.m:178 POST 'https://api.myURL.com/api/0_0_1/notify/player': 
request.headers= 
{ 
    Accept = "application/json"; 
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5"; 
    "Content-Type" = "application/json; charset=utf-8"; 
    "User-Agent" = "game/1470 (iPhone; iOS 7.1; Scale/2.00)"; 
} 
request.body= 
{ 
    "game":"539e75acadae8fb03900057e", 
    "to":"533bd7eb5317b88f61000006", 
    "message":"‎Ben Fowler is waiting for you to play the game", 
    "from":"5332b4f5edfc9beb7900004d" 
} 
2014-06-16 15:58:08.856 game[5961:5607] T restkit.network:RKObjectRequestOperation.m:248 POST 'https://api.myURL.com/api/0_0_1/notify/player' (200 OK/1 objects) [request=1.6911s mapping=0.0020s total=1.6989s]: 
     response.headers={ 
      Connection = "keep-alive"; 
      "Content-Length" = 42; 
      "Content-Type" = "application/json; charset=utf-8"; 
      Date = "Mon, 16 Jun 2014 07:58:09 GMT"; 
      "X-Powered-By" = Express; 
     } 
     response.body= 
     { 
      "result": 1, 
      "notify": "871720292" 
     } 

La classe cartographié

-(void)WtfGameNotifcationResponse 
{ 
RKObjectMapping *notifyMapping = [RKObjectMapping mappingForClass:[WTFGameNotification class]]; 

[notifyMapping addAttributeMappingsFromDictionary: 
@{ 
@"result" : @"result", 
@"notify" : @"notifyID", 
}]; 

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:notifyMapping 
                         method:RKRequestMethodGET 
                        pathPattern:@"notify/player" 
                         keyPath:nil 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor]; 

}

La classe en question

@interface WTFGameNotification : NSObject 

@property (nonatomic,copy) NSString* to; 
@property (nonatomic,copy) NSString* from; 
@property (nonatomic,copy) NSString* gameID; 
@property (nonatomic,copy) NSString* message; 

@property (nonatomic,strong) NSNumber* result; 
@property (nonatomic,copy) NSString *notifyID; 

+ (WTFGameNotification*)Create; 

@end 

Répondre

0

Il semble que si vous essayez pour mapper un réponse d'un POST c'est la méthode et la syntaxe à utiliser.

+ (void)SendNotification:(GameInfo*)gameInfo withMessage:(NSString*)message forView:(UIViewController*)view 
{ 
    WTFGameNotification *_wtfGameNotif = [WTFGameNotification Create]; 

    [_wtfGameNotif setTo:[gameInfo opponentWTFID]]; 
    [_wtfGameNotif setFrom:[PlayerWTFInfo Load]._wtfID]; 
    [_wtfGameNotif setGameID:[gameInfo gameID]]; 
    [_wtfGameNotif setMessage:message]; 

    if ([_wtfGameNotif to] && [_wtfGameNotif gameID]) 
    { 
     RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] appropriateObjectRequestOperationWithObject:_wtfGameNotif 
                                method:RKRequestMethodPOST 
                                 path:nil 
                               parameters:nil]; 
     RFResponse *r1 = [RFResponse new]; 
     operation.targetObject = r1; 

     [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) 
     { 
      if (r1.result.integerValue != 0) 
      { 
       [Utilities FacebookPostWithResult:@{@"fbId": r1.notify}]; 
      } 
     } 
     failure:^(RKObjectRequestOperation *operation, NSError *error) 
     { 
      DDLogError(@"POST REQUEST FAILED IN CONFIRMFOTOVC : %@",[error description]); 

      if (view) 
      { 
       [LoadingView PopToRootShutterCloseOnView:view willOpen:YES]; 
      } 
     }]; 

     [operation start]; 

    } 
    else 
    { 
     DDLogInfo(@"NO PLAYER ID"); 
    } 
} 
0

Si vous envoyez des messages l'objet au serveur, le descripteur de réponse que vous avez ne correspondra pas parce que vous liez à un GET avec method:RKRequestMethodGET. Vous devez changer cela à method:RKRequestMethodPOST. Lorsque vous utilisez un modèle de chemin de @"notify/player", l'URL de base doit être définie sur https://api.myURL.com/api/0_0_1/, mais cela ne semble pas être un problème pour vous.