objective-c - RestKit iOS 应用程序根据请求崩溃

标签 objective-c ios crash ios6 restkit

我对 Objective C 和 RestKit 有一个大问题。 在应用程序启动时,我想单击一个按钮。 但是,如果我在启动后立即单击按钮,我的应用程序就会崩溃。 如果我等待几秒钟,一切都会正常。

有人有想法吗? 这是我的代码

- (void)sendRequest {
// Perform a simple HTTP GET and call me back with the results
[[RKClient sharedClient] get:@"/user" delegate:self];
}

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
  if ([response isSuccessful]) {
    NSLog(@"HTTP status code:     %d", response.statusCode);
    NSLog(@"HTTP status message:  %@", [response localizedStatusCodeString]);
  }
}

启动后客户端会在“AppDelegate”中创建

RKClient *client = [RKClient clientWithBaseURLString:@"http://192.168.0.6:8080"];
[client setPassword:@"user"];
[client setUsername:@"user"];
[client setAuthenticationType:RKRequestAuthenticationTypeHTTPBasic];
client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;

按下按钮后将调用“sendRequest”方法。

抱歉,我的英语不是很好。 我希望你理解我的问题。

最佳答案

我也有同样的问题.. 能够用 block 解决这个问题

NSURL *baseURL = [[NSURL alloc] initWithString:@"http://your.api.com"];
RKClient *client = [RKClient clientWithBaseURL:baseURL];

RKRequest *request = [client get:@"/method/name" queryParameters:nil delegate:nil];
request.onDidLoadResponse = ^(RKResponse *response) {
    NSLog(@"%@", [response bodyAsString]);
};

关于objective-c - RestKit iOS 应用程序根据请求崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13182181/

相关文章:

iphone - Cocos2d (iOS) + SneakyInput。处理操纵杆(游戏 handle )事件的最佳方式?

android - 更新AndroidManifest.xml时ActivityThread.handleBindApplication崩溃,回滚仍然崩溃

objective-c - iOS 10.3.3 UIButton _intrinsicSizeWithinSize/_updateTitleView CoreFoundation 崩溃

ios - 带图像的 SKSpriteNode 不会着色

objective-c - 为什么我的 IBOutlet 标签中没有创建新行?

ios - Xcode 6 - 将导航 Controller 添加到 Storyboard,但未出现在应用程序中

ios - 根据 TableViews 自定义单元格中点击的图像执行 segue

ios - dyld_fatal_error 与 Typhoon+Swift+iOS7.x+Plist-bootstrapping

MySQL 因 Unresolved 内存问题而崩溃

objective-c - SSL 和 NSStream