2

RestKit 0.20 にアップデートしたばかりで、Album オブジェクトがマップされない理由を突き止めようとして、デスクトップに頭をぶつけています。応答オブジェクトには keyPath がありませんが、以前は @"" に設定することで機能していました。

返されるデータのスニペットを次に示します。

[
  {
    id: "337",
    title: "Hockey",
    description: "",
    location: "",
    date_created: "1353424563",
    date_modified: "1353424563",
    featured_image: "album_default.png",
    featured_thumb_link: "http://test1.keepsayk.com//images/album_default.jpg",
    featured_main_link: "http://test1.keepsayk.com/img/album_default.png",
    feat_img_type: "image",
    public: "0",
    default_album: "",
    owner_fname: "Mike",
    owner_lname: "Rose",
    owner_id: "102",
    recent_media: false,
    last_media_added_date: false,
    tags: [ ],
    circles: [],
    media: [ ],
    image_count: 0,
    video_count: 0,
    text_count: 0,
    audio_count: 0,
    comments: [ ],
    scrapbook: [ ]
  },
  {
    id: "336",
    title: "Bull",
    description: "",
    location: "",
    date_created: "1353420585",
    date_modified: "1353420585",
    featured_image: "album_default.png",
    featured_thumb_link: "http://test1.keepsayk.com//images/album_default.jpg",
    featured_main_link: "http://test1.keepsayk.com/img/album_default.png",
    feat_img_type: "image",
    public: "0",
    default_album: "",
    owner_fname: "Mike",
    owner_lname: "Rose",
    owner_id: "102",
    recent_media: false,
    last_media_added_date: false,
    tags: [ ],
    circles: [],
    media: [ ],
    image_count: 0,
    video_count: 0,
    text_count: 0,
    audio_count: 0,
    comments: [ ],
    scrapbook: [ ]
  },
  ...
]

アプリデリゲートのコードは次のとおりです。

// restkit object manager
    _objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://test1.keepsayk.com"]];
    [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;

// restkit object store
    _objectManager.managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:[self managedObjectModel]];
    [_objectManager.managedObjectStore createPersistentStoreCoordinator];
    [_objectManager.managedObjectStore createManagedObjectContexts];

// setup album object
RKEntityMapping *albumEntityMapping = [RKEntityMapping mappingForEntityForName:@"KeepsaykAlbum" inManagedObjectStore:_objectManager.managedObjectStore];
    albumEntityMapping.identificationAttributes = @[@"identifier"];
    [albumEntityMapping addAttributeMappingsFromDictionary:@{ @"id" : @"identifier", @"title" : @"keepsaykTitle", @"description" : @"keepsaykDescription", @"date_created" : @"dateCreated", @"date_modified" : @"dateModified", @"featured_thumb_link" : @"featuredImageThumbLink", @"featured_main_link" : @"featuredImageLink", @"public" : @"isPublic", @"default_album" : @"isDefaultAlbum", @"owner_fname" : @"ownerFirstName", @"owner_lname" : @"ownerLastName", @"owner_id" : @"ownerIdentifier", @"last_media_added_date" : @"dateMediaModified", @"image_count" : @"imageCount", @"video_count" : @"videoCount", @"text_count" : @"textCount", @"audio_count" : @"audioCount", @"scrapbook" : @"scrapbookLayouts" }];

    [_objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:albumEntityMapping pathPattern:@"albums/display/:userID/:apiKey" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];

別のクラスで get メソッドを呼び出します。リソース パスはログでトレースされます。

- (void)loadObjectsFromResourcePath:(NSString *)resourcePath;
{
    NSLog(@"resource path: %@", resourcePath);

    [RKObjectManager.sharedManager getObjectsAtPath:resourcePath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        NSLog(@"mapping result: %@", [mappingResult array]);
        [self stopLoading];
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@", error);
        [self stopLoading];
    }];
}

ここに私のエラーログがあります:

   2012-12-04 17:48:47.437 Keepsayk Alpha[9036:907] I restkit:RKLog.m:34 RestKit logging initialized...
    2012-12-04 17:48:47.703 Keepsayk Alpha[9036:907] I restkit.support:RKMIMETypeSerialization.m:115 JSON Serialization class 'RKNSJSONSerialization' detected: Registering for MIME Type 'application/json
2012-12-04 17:48:47.696 Keepsayk Alpha[9036:907] resource path: albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba
    2012-12-04 17:48:47.708 Keepsayk Alpha[9036:1603] I restkit.network:RKHTTPRequestOperation.m:141 GET 'http://test1.keepsayk.com/albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba'
    2012-12-04 17:48:47.711 Keepsayk Alpha[9036:907] error (null), (null)
    2012-12-04 17:48:48.995 Keepsayk Alpha[9036:372f] I restkit.network:RKHTTPRequestOperation.m:158 GET 'http://test1.keepsayk.com/albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba' (200)
    2012-12-04 17:48:49.011 Keepsayk Alpha[9036:907] error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "Unable to find any mappings for the given content" UserInfo=0x1d5b7e40 {DetailedErrors=(
    ), NSLocalizedDescription=Unable to find any mappings for the givn content, keyPath=null}
4

3 に答える 3

0

keyPathを@""ではなくnilに設定します

于 2012-12-05T03:54:19.480 に答える
0

それでもこのエラーが発生する場合は、「/」を確認して、baseURL とパスを組み合わせるときに「www.mybase.com//blah/blah.json」にならないようにしてください。また、2012 年 12 月 8 日の時点で、最新の Restkit コードに更新すると、わずかな修正が得られるはずです。Blake は、実行時に 1001 よりもわかりやすい警告を表示するコードを追加しました。

于 2012-12-09T04:29:45.980 に答える
0

リソース パスに最初の「/」がありませんでした。

[_objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:albumEntityMapping pathPattern:@"/albums/display/:userID/:apiKey" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
于 2012-12-05T19:33:34.400 に答える