2013-01-02 3 views
8

RESTKit을 배우고 있으며 이전 버전의 RESTKit에 따른 this 자습서를 따르고 있으며 v0.20.0에서 많은 변경이 있었기 때문에 새 버전에 대해 읽고 있습니다. 튜토리얼에서와 같은 작업을 수행합니다.RESTKit 관련 문제가 제대로 매핑되지 않았습니다.

이제 매핑에 문제가 있으며 성공하지 못하면서 많은 시간을 보냈습니다. 나는 점점 오전 오류 :

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 "Venue.h" 

@implementation Venue 
@synthesize name; 

@end 

내가 ViewDidAppear 방법에 MasterViewController.m에 최선을 다하고 있어요 :

#import <Foundation/Foundation.h> 

@interface Venue : NSObject 

@property (strong, nonatomic) NSString *name; 

@end 

Venue.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); 
         }]; 

} 

I hav e는 브라우저에서 응답을 확인했으나 괜찮습니다. 그러나 어떤 이유로 든 오류를 제거하지 않았습니다. 나는 매핑의 첫 번째 단계에 갇혀 있으며 앞으로 나아갈 수 없습니다. 인터넷상의 주제에 대한 모든 예제와 문서는 구식이며 RESTKit의 이전 버전에 대한 경험이 없기 때문에 나는 그 사실을 알 수 없다. 내가 뭘 잘못하고 있는지 말해줘.

xcode 4.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"}, ..... 

답변

12

정확히 동일한 튜토리얼을 0.20 버전으로 변환하고 마지막으로 URL을 소문자로 만드는 것이 수정되었습니다 (https://api.Foursquare.com/v2). 대문자 'F'를 소문자 f로 바꾸십시오. 따라서 모두 소문자입니다. RESTKit은 모든 소문자를 예상하며 대소 문자를 구분하지만, iOS 프로그래밍 및 RESTKit은 처음 사용하는 것으로 보입니다. 난 당신이 이미이를 믿는다 "response.venues"

@,하지만 난 원 :

  1. RKRelationshipMapping 물건에 대한 필요가 없습니다
  2. pathPattern : & 전무 키 패스를

    또한주의 단지 경우에 따라 길다.

+0

고마워, 나는 이것이 문제가 될 것이라고 결코 예상하지 못했고 튜토리얼을 v0.20로 바꾸려는 노력에 감사한다. – SpeedBirdNine

+0

@Tilo 변환 된 자습서는 어디에서 찾을 수 있습니까? 꽤 도움이 될 것입니다. – Danny

0

은 단순히 "장소"대신 "response.venues"로 키 패스를 시도?

+0

예, 성공하지 못했습니다. – SpeedBirdNine

0

당신이 사용자 정의 HTTP 클라이언트와 base을 사용했습니다 때문에 그냥 경로 확장 사용해보십시오 :

[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); 
        }]; 

을 또한 응답 설명자에 경로를 추가 : I 시도

RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:venueMapping 
                        pathPattern:@"/venues/search" 
                         keyPath:@"venues" 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 
+0

시도해 보니 성공하지 못했습니다. 필자는이 빌드와 구버전 RestKit (0.10.x)하지만 어떤 이유로 최신 버전으로 작업 할 수 없습니다. – SpeedBirdNine

관련 문제