0

开始我的 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 的最简单的代码示例,只是为了看看这个东西是否有效?

4

1 回答 1

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

于 2012-12-06T20:54:27.717 回答