ios - RestKit mapping issue. Same Keypaths, different path patterns & request methods -


i'm having problem restkit.

i configure responsedescriptors map post requests /users/login generalresponsemapping , get requests /users/:userid usermapping.

init code:

rkobjectmanager *objectmanager = [rkobjectmanager managerwithbaseurl:baseurl];      ...  rkobjectmapping *generalresponsemapping = [rkobjectmapping mappingforclass:[nsmutabledictionary class]]; [generalresponsemapping addattributemappingsfromarray:@[ @"status", @"token" ]];  rkentitymapping *usermapping = [rkentitymapping mappingforentityforname:@"user" inmanagedobjectstore:managedobjectstore]; usermapping.identificationattributes = @[ @"userid" ]; [usermapping addattributemappingsfromarray:@[ @"avatar", @"name", @"email" ]];   void(^configureresponse)(rkmapping *,        rkrequestmethod,        nsstring *,        nsstring *,        nsindexset *) =                        ^(rkmapping *mapping, rkrequestmethod method, nsstring *pattern, nsstring *keypath, nsindexset *statuscodes) {     rkresponsedescriptor *responsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:mapping                                                                                             method:method                                                                                        pathpattern:pattern                                                                                            keypath:keypath                                                                                        statuscodes:statuscodes];     [objectmanager addresponsedescriptor:responsedescriptor]; };  nsindexset *codes = rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful);  configureresponse(generalresponsemapping, rkrequestmethodpost, @"users/login",   nil, codes);    configureresponse(usermapping,            rkrequestmethodget,  @"users/:userid", nil, codes);      ... 

but when try send post request /users/login.

- (void)loginwithuserdata:(nsdictionary *)userdata {        nsstring *path = @"users/login";      rkobjectmanager *objectmanager = [rkobjectmanager sharedmanager];     [objectmanager postobject:nil                          path:path                    parameters:userdata                       success:^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult)  {     ...  }                       failure:^(rkobjectrequestoperation *operation, nserror *error)  {     ...  }]; } 

i error because restkit trying map generalresponse object usermapping

restkit.object_mapping:rkmapperoperation.m:231 asked map source object {     status = 0;     token = "some_fake_token"; } mapping <rkentitymapping:0x9bb9040 objectclass=user propertymappings=(     "<rkattributemapping: 0x9bc5980 avatar => avatar>",     "<rkattributemapping: 0x9b64dc0 name => name>",     "<rkattributemapping: 0x9bc5700 email => email>",     "<rkattributemapping: 0x9bc6a20 id => userid>", )> 

how can map responses both paths appropriate mappings without rearranging objectmanagers responsedescriptors before every request?

upd

log of restkit network module:

restkit.network:rkobjectrequestoperation.m:178 post 'http://api.myapp.com/users/login': 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/x-www-form-urlencoded; charset=utf-8"; "user-agent" = "myapp/666 (iphone simulator; ios 7.0; scale/2.00)"; } request.body=email=t&password=t 

if comment out addition of responsedescriptor users/:userid can right mapping , network module log:

restkit.network:rkobjectrequestoperation.m:248 post 'http://api.myapp.com/users/login' (200 ok / 1 objects) [request=0.0286s mapping=7.6855s total=7.7190s]: response.headers={ "cache-control" = "max-age=0, private, must-revalidate"; connection = "keep-alive"; "content-type" = "application/json; charset=utf-8"; date = "mon, 07 oct 2013 23:18:06 gmt"; etag = "\"555dbdf216a0f30229810af9411ad7c9\""; "keep-alive" = "timeout=20"; server = nginx; status = "200 ok"; "transfer-encoding" = identity; "x-content-type-options" = nosniff; "x-frame-options" = sameorigin; "x-request-id" = "07803850-cfe3-4ccb-9a0d-46be980b0537"; "x-runtime" = "0.004017"; "x-ua-compatible" = "chrome=1"; "x-xss-protection" = "1; mode=block"; } response.body={"status":0,"token":"some_fake_token"} 

otherwise exc_bad_access in end of @autoreleasepool block in -[rkmapperoperation mapsourcerepresentationwithmappingsdictionary] , network block logging stays quiet.

not sure request type should provide split required. line:

nsstring *path = @"/users/login"; 

change to:

nsstring *path = @"users/login"; 

adding slashes 1 part of path pattern , not (on response descriptors) can cause failures when restkit tries match them.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -