8

私はRESTKitを学習しており、以前のバージョンのRESTKitに準拠したこのチュートリアルに従っていますが、v0.20.0では多くの変更が加えられているため、新しいバージョンについて読み、チュートリアルと同じタスクを実行しています。

現在、マッピングに問題があり、私はそれに何時間も費やして成功しませんでした。私が得ているエラーは次のとおりです。

error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x758d320 {NSErrorFailingURLStringKey=https://api.foursquare.com/v2/venues/search?client_id=<client id>&client_secret=KYHQHRYJ4PYFJYEG1F1IQVLQDM4G1HZ1STB2O1VUVUVQZBGS<client secret>&ll=37.33,-122.03&query=coffee&v=20120602, NSLocalizedFailureReason=A 200 response was loaded from the URL 'https://api.foursquare.com/v2/venues/search?client_id=<client id>&client_secret=<client secret>&ll=37.33,-122.03&query=coffee&v=20120602', which failed to match all (1) response descriptors:
  <RKResponseDescriptor: 0x9566a60 baseURL=https://api.Foursquare.com/v2/ pathPattern=(null) statusCodes=200-299> failed to match: response URL 'https://api.foursquare.com/v2/venues/search?client_id=<client id>&client_secret=<client secret>&ll=37.33,-122.03&query=coffee&v=20120602' is not relative to the baseURL 'https://api.Foursquare.com/v2/'., NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=https://api.foursquare.com/v2/venues/search?client_id=<client id>&client_secret=<client secret>&ll=37.33,-122.03&query=coffee&v=20120602, NSUnderlyingError=0x758d3a0 "No mappable object representations were found at the key paths searched."}

Venue.hは:

#import <Foundation/Foundation.h>

@interface Venue : NSObject

@property (strong, nonatomic) NSString *name;

@end

Venue.mは:

#import "Venue.h"

@implementation Venue
@synthesize name;

@end

そして、私はViewDidAppearメソッドのMasterViewController.mですべてを実行しています。これは次のとおりです。

- (void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSURL *baseURL = [NSURL URLWithString:@"https://api.Foursquare.com/v2"];

    AFHTTPClient * client = [AFHTTPClient clientWithBaseURL:baseURL];
    [client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];

    RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];

    RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]];
    [venueMapping addAttributeMappingsFromDictionary:@{
     @"name" : @"name"
     }];

    RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:venueMapping
                                                                                        pathPattern:nil
                                                                                            keyPath:@"response.venues"
                                                                                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
    [objectManager addResponseDescriptor:responseDescriptor];

    NSString *latLon = @"37.33,-122.03";
    NSString *clientID = [NSString stringWithUTF8String:kCLIENTID];
    NSString *clientSecret = [NSString stringWithUTF8String:kCLIENTSECRET];

    NSDictionary *queryParams;
    queryParams = [NSDictionary dictionaryWithObjectsAndKeys:latLon, @"ll", clientID, @"client_id", clientSecret, @"client_secret", @"coffee", @"query", @"20120602", @"v", nil];
    //NSLog(@"object manager: %@ - %@", objectManager.baseURL, [[objectManager responseDescriptors] objectAtIndex:0]);

    /*
    RKRelationshipMapping* relationShipMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"venues"
                                                                                             toKeyPath:@"venues"
                                                                                           withMapping:venueMapping];
    [venueMapping addPropertyMapping:relationShipMapping]; */
    [objectManager getObjectsAtPath:@"https://api.Foursquare.com/v2/venues/search"
                         parameters:queryParams
                         success:^(RKObjectRequestOperation * operaton, RKMappingResult *mappingResult)
                         {
                             NSLog(@"success: mappings: %@", mappingResult);
                         }
                         failure:^(RKObjectRequestOperation * operaton, NSError * error)
                         {
                             NSLog (@"failure: operation: %@ \n\nerror: %@", operaton, error);
                         }];

}

ブラウザで応答を確認しましたが、問題はありませんが、何らかの理由でエラーを取り除くことができませんでした。マッピングの最初のステップで立ち往生していて、先に進むことができません。インターネット上の主題に関するすべての例とドキュメントは古く、RESTKitの古いバージョンの経験がないので私は物事を理解することができません。私が間違っていることを教えてください。

xcode4.5を使用してiOS6用にビルドします。

応答は(ブラウザでチェック):

{"meta":{"code":200},"response":{"venues":[{"id":"4f482132e4b0f85d07c34cb5","name":"De Anza 3 Coffee Bar","contact":{},"location":{"address":"10500 De Anza Blvd","lat":37.329438,"lng":-122.03083,"distance":96,"postalCode":"95014","city":"Cupertino","state":"CA","country":"United States","cc":"US"},"canonicalUrl":"https:\/\/foursquare.com\/v\/de-anza-3-coffee-bar\/4f482132e4b0f85d07c34cb5","categories":[{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"},"primary":true}],"verified":false,"restricted":true,"stats":{"checkinsCount":1,"usersCount":1,"tipCount":0},"likes":{"count":0,"groups":[]},"specials":{"count":0,"items":[]},"hereNow":{"count":0,"groups":[]},"referralId":"v-1357121711"},{"id":"40ccea80f964a52019011fe3","name":"Coffee Society","contact":{"phone":"4087258091","formattedPhone":"(408) 725-8091"},"location":{"address":"21265 Stevens Creek Blvd","crossStreet":"at Oaks Shopping Center","lat":37.32330342,"lng":-122.047382,"distance":1709,"postalCode":"95014","city":"Cupertino","state":"CA","country":"United States","cc":"US"},"canonicalUrl":"https:\/\/foursquare.com\/v\/coffee-society\/40ccea80f964a52019011fe3","categories":[{"id":"4bf58dd8d48988d1e0931735","name":"Coffee Shop","pluralName":"Coffee Shops","shortName":"Coffee Shop","icon":{"prefix":"https:\/\/foursquare.com\/img\/categories\/food\/coffeeshop_","sizes":[32,44,64,88,256],"name":".png"},"primary":true}],"verified":false,"restricted":true,"stats":{"checkinsCount":2536,"usersCount":869,"tipCount":24},"likes":{"count":0,"groups":[]},"specials":{"count":0,"items":[]},"hereNow":{"count":0,"groups":[]},"referralId":"v-1357121711"}, .....
4

4 に答える 4

12

まったく同じチュートリアルをバージョン 0.20 に変換しようとしましたが、最終的にそれを修正したのは、URL を小文字 (https://api.Foursquare.com/v2) にすることでした。その大文字の「F」を小文字の f に置き換えて、すべて小文字にします。RESTKit はすべて小文字を想定しており、大文字と小文字を区別しているようですが、私は iOS プログラミングと RESTKit は初めてです。

また、次の点に注意してください。

  1. RKRelationshipMapping の必要はありません
  2. pathPattern:nil & keyPath:@"response.venues"

これらはすでにお持ちだと思いますが、念のため詳しく説明したいと思います。

于 2013-01-10T21:29:20.893 に答える
1

ここに来て CAPS の問題を抱えていない人 (私のように) は、RestKit の作成者によるこの github resolution post をチェックしてください。パスの問題を理解するのに役立ちました。

于 2013-04-29T01:27:46.310 に答える
0

カスタムHTTPクライアントでbaseURLを使用したので、パス拡張子だけを使用してみてください。

 [objectManager getObjectsAtPath:@"/venues/search"
                     parameters:queryParams
                     success:^(RKObjectRequestOperation * operaton, RKMappingResult *mappingResult)
                     {
                         NSLog(@"success: mappings: %@", mappingResult);
                     }
                     failure:^(RKObjectRequestOperation * operaton, NSError * error)
                     {
                         NSLog (@"failure: operation: %@ \n\nerror: %@", operaton, error);
                     }];

また、応答記述子にパスを追加します。

RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:venueMapping
                                                                                    pathPattern:@"/venues/search"
                                                                                        keyPath:@"venues"
                                                                                    statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
于 2013-01-04T00:08:49.250 に答える
0

keyPathを「response.venues」ではなく単に「venues」として試しましたか?

于 2013-01-02T18:03:48.017 に答える