iphone - iOS RestKit Framework - 发送请求后崩溃

标签 iphone objective-c ios http restkit

我的代码:

RKRequest.m:

#import "RKRequestDelegate.h"
#import "Constants.h"


@implementation RKRequestDelegate {

}

- (void)sendRequest:(UIImageView *)imageView {

    NSDictionary *queryParams = [NSDictionary dictionaryWithObjectsAndKeys:@"0", @"w", @"4", @"section", @"0",
                                                                           @"latitude", @"0", @"longitude", @"0", @"dt", @"0", @"di", nil];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:[Constants getSettingsName]
            ofType:[Constants getSettingsFormat]];
    NSDictionary *contentDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    NSString *addedUrl = [contentDictionary valueForKey:[Constants getBannerTag]];
    //

    RKRequest *request = [[RKClient sharedClient] get:addedUrl queryParameters:queryParams delegate:self];
}

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
    NSLog(@"Response!!!");
}


@end

RKRequestDelegate.h:

@interface RKRequestDelegate : NSObject <RKRequestDelegate>

- (void)sendRequest:(UIImageView *)UIImageView;
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response;

@end

AppDelegate.m:

    RKClient *client = [RKClient clientWithBaseURL:[HttpUtil getHost]];

启动应用程序后,它会在 5 秒后崩溃。如果我将 delegate:self 更改为 delegate:[RKRequestDelegate class] 它不会崩溃,并给出响应 200(OK),但它没有回调 didLoadResponse !

请帮忙,谢谢。

更新:

如果我在 RKRequestDelegate.m 中使用 [request sendSynchronously];,就会调用 response。

最佳答案

使request成为一个类变量。

编辑:这是一些代码,没有在现实生活中检查过,但这种方式应该有效

   @interface MYRequests : NSObject<RKRequestDelegate>
   {
       RKRequest *request;
   }

   @implementation MYRequests
   - (void)loginRequest
   {
       request = [RKRequest ...];
       request.method = RKRequestMethodGET;
       request.delegate = self;
       [request send];
   }
   @end

关于iphone - iOS RestKit Framework - 发送请求后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11322796/

相关文章:

objective-c - 帮助 GCC 和 ObjectiveC 代码以及 Cygwin

iphone - 如何为应用程序商店起一个长名称,然后在图标下起一个短名称?

ios - 如何在 SpriteKit 上创建 UITextField

ios - 无法在 iOS 模拟器中缩放设备窗口

iphone - coreLocation多久更新一次

objective-c - 获取展示应用

ios - 在 NavigationBarHidden 之后,StatusBar 太糟糕了

ios - iOS-如何在UIWebView上自动播放youtube视频或直接与任何Video Player一起播放?

css - iPhone 忽略所有媒体查询

iphone - 合并暂定定义时 iOS 对齐丢失