1

RestEngine クラスが確立されたときに、すべての responseDescriptors (8 つ) とマッピング (8 つ) を設定するプロジェクトがあります...各呼び出しではなく、事前にそれらを設定します。この良い習慣かどうかはわかりません。

問題は、ディスクリプタの 1 つがすべての結果をマッピングすべきではないときにマッピングしているように見えることです。

問題は私のthingDescriptorにあるか、次のルート(v1/things/:thingID\.json)である可能性があると思いますが、このルートはGETであるため、POSTリクエストがこのルートを通過するとは思いませんか?

これは、特定のクラスにマップされるべきではない、または特定のクラスにマップされたくない結果を取得している、私が作成している POST 要求です。

[[RKObjectManager sharedManager] postObject:nil
                                           path:@"v1/things/request.json"
                                     parameters:@{
                                                     @"auth_token" : self.accessToken,
                                                     @"api_key" : self.api_key,
                                                     @"lat" : lat,
                                                     @"lng" : lng
                                                 }
                                        success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                            RKLogInfo(@"Post request of an Thing Request start tracking request update...");

<-- the mappingResult shows its mapped to a Thing class but I want server response to mapped to an NSDictionary instead? 

                                        }
                                        failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                            RKLogError(@"Post request of an Thing Request failed with error: %@", error);
                                        }];

セットアップされている私のマッピングは次のとおりです。

// Routes for Things
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
                                                    pathPattern:@"v1/things/:thingID\\.json"
                                                         method:RKRequestMethodGET]];


[objectManager.router.routeSet addRoute:[RKRoute routeWithName:kRouteUpdateThingLoc
                                                   pathPattern:@"v1/things/update_location.json"
                                                        method:RKRequestMethodPOST]];

 [objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
                                                    pathPattern:@"v1/things.json"
                                                         method:RKRequestMethodPOST]];

// Register our mappings with the provider
RKResponseDescriptor *thingResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:thingMapping
                                                                                       pathPattern:@"v1/things.json"
                                                                                           keyPath:nil
                                                                                       statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

RKResponseDescriptor *thingDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:thingMapping
                                                                               pathPattern:@"v1/things/:thingID.json"
                                                                                   keyPath:nil
                                                                               statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
4

2 に答える 2

1

AFNetworking を次のように使用します。

    AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:@"v1/"];

    NSDictionary *parameters = @{
                                @"auth_token" : self.accessToken,
                                @"api_key" : self.api_key,
                                @"lat" : lat,
                                @"lng" : lng
                                };

    NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"things/request.json" parameters:parameters];

    AFJSONRequestOperation *opertaion = [AFJSONRequestOperation JSONRequestOperationWithRequest:responseObject success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSLog(@"THIS IS A DICTIONARY (or array): %@", JSON);
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"if requestFailed");
    }];
于 2013-05-01T02:20:27.320 に答える