RestKit 0.20pre2请求后没有响应

时间:2012-12-06 17:31:12

标签: ios restkit

开始我的RestKit开发,尝试发出第一个请求。从Github获取此示例代码,为我的类修改,但在设备上运行后我没有看到任何活动迹象。即没有回调,没有崩溃,没有例外,没有记录输出。我拿错了吗?这是代码:

    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[FavoritePlace class]];

    [mapping addAttributeMappingsFromDictionary:@{@"name": @"name", @"placeId": @"id"}];

    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:@"/favoritePlace/:placeID" keyPath:@"id" statusCodes:statusCodes];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://my.internal.url/v20"]];

    RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];

    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
        FavoritePlace *place = [result firstObject];
        NSLog(@"Mapped the place: %@", place);
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"Failed with error: %@", [error localizedDescription]);
    }];

我正在使用https,你可以看到 - 支持吗?

作为奖励,任何人都可以为0.20 API提供最简单的代码示例,只是为了看看这个东西是否有效?

1 个答案:

答案 0 :(得分:0)

在我看来,最好的方法是检查RKTwitterCoreData应用程序示例,它总是在进行新提交时更新。您可以在此处查看示例项目:https://github.com/RestKit/RestKit/tree/master/Examples/RKTwitterCoreData

根据您粘贴的内容,您的代码看起来很好。您是否在应用代理中初始化了RestKit?见这里:https://github.com/RestKit/RestKit/blob/master/Examples/RKTwitterCoreData/Classes/RKTwitterAppDelegate.m

如果您使用Core Data,则必须设置托管对象存储,持久存储等。

API浏览器中还有很多文档,例如RKObjectManager:http://restkit.org/api/0.20.0-pre2/Classes/RKObjectManager.html