我一直试图让 RestKit 在我的应用程序上工作,但没有成功。我有一个启用 ARC 的应用程序,我使用https://github.com/RestKit/RestKit/wiki/Installing-RestKit-in-Xcode-4.x安装了它。我一直在阅读 StackOverflow 上的文章,说我需要一个单例类或其他东西。我回到基础并尝试按照以下示例进行操作:https ://github.com/RestKit/RestKit/wiki/Tutorial-%3A-Introduction-to-RestKit 。
在我的 AppDelegate 中,我有:
RKClient *client = [RKClient clientWithBaseURLString:@"http://restkit.org"];
NSLog(@"I am your RKClient singleton: %@", [RKClient sharedClient]);
在我的另一堂课上,我有:
- (void) sendRequests {
[[RKClient sharedClient] get: @"/foo.xml" delegate:self];
NSDictionary *params = [NSDictionary dictionaryWithObject:@"RestKit" forKey:@"Sender"];
[ [RKClient sharedClient] post:@"/other.json" params:params delegate:self];
// DELETE a remote resource from the server
[ [RKClient sharedClient] delete:@"/missing_resource.txt" delegate:self];
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
if ([request isGET]) {
// Handling GET /foo.xml
if ([response isOK]) {
// Success! Let's take a look at the data
NSLog(@"Retrieved XML: %@", [response bodyAsString]);
}
} else if ([request isPOST]) {
// Handling POST /other.json
if ([response isJSON]) {
NSLog(@"Got a JSON response back from our POST!");
}
} else if ([request isDELETE]) {
// Handling DELETE /missing_resource.txt
if ([response isNotFound]) {
NSLog(@"The resource path '%@' was not found.", [request resourcePath]);
}
}
}
- (void) requestWillPrepareForSend:(RKRequest *)request {
NSLog(@"request: %@",request);
}
我收到 EXC_BAD_ACCESS(code -1, address = 0x766c6550) 错误,它指向的行是:
if ([self.delegate respondsToSelector:@selector(requestWillPrepareForSend:)]) {
顺便说一句,我通过执行以下操作调用 getRequest:
RestHandler *myRestHandler = [[RestHandler alloc] init];
[myRestHandler sendRequests];
和 RestHandler 确实有 .
谁能在这里为我提供一些见解?我读了一堆关于 StackOverflow 的文章,但我回到了基础,仍然无法弄清楚。
谢谢!