0
    In ClassA.h
    @interface ClassA : NSObject<RKObjectLoaderDelegate,RKRequestDelegate>
    @property(nonatomic,strong)NSMutableDictionary *inputDict;

     ClassA.m
//After Implementation
      @synthesize inputDict;

        -(void)sendRequestWithInputDict:(NSMutableDictionary*)inputDictVal
        {
        RKURL *baseURL = [RKURL URLWithBaseURLString:baseUrl];
           RKObjectManager * manager = [RKObjectManager objectManagerWithBaseURL:baseURL];  
            [manager setClient:[RKClient sharedClient]];


            manager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
            RKObjectLoader *objectLoader = [manager loaderWithResourcePath:@"/getLocation"];  
            objectLoader.serializationMIMEType = RKMIMETypeJSON;
            objectLoader.method = RKRequestMethodPOST;
            objectLoader.params = inputDictVal;
            objectLoader.delegate = self;
            [objectLoader send];
        }

     -(void)getLocation
   {
      inputDict = [[NSMutableDictionary alloc]init];
     [self sendRequest:inputDict];
   }

baseUrl 在我在这里导入的常量文件中声明。我正在尝试从另一个类调用 sendRequest 函数。但是我在 requestWillPrepareForSend(RKRequest.m) 中得到一个 EX_BAD_ACCESS。

我认为某些对象会自动释放。我不知道是哪一个...

4

3 回答 3

0

There are many things that are wrong with your code. The most obvious is not retaining the object manager (unless this becomes the sharedManager) another is trying to load an object but using POST. Although, judging by the errors you report, I think your ClassA instance is being dealloced, and because it is set as a delegate you are getting EXC_BAD_ACCESS. I suggest you move to using the block based methods and not the delegate callbacks.

于 2012-08-21T06:48:36.693 回答
0

通过使用 Blocks,我可以向服务器发送请求并从中获取响应。我在这里找到了很好的教程http://kalapun.com/blog/2012/05/17/how-i-restkit/

-(void)sendRequest:(NSMutableDictionary*)inputDict withResourcePath:(NSString*)resourcePath
{
     RKURL *baseURL = [RKURL URLWithBaseURLString:baseUrl];
        RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL:baseURL];  
        [manager setClient:[RKClient sharedClient]];


        [manager loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *objectLoader){


        objectLoader.method = RKRequestMethodPOST;
        objectLoader.params = inputDict;

        objectLoader.onDidFailWithError = ^(NSError *error){

        NSLog(@"Error: %@", [error localizedDescription]);

        };
        objectLoader.onDidLoadResponse = ^(RKResponse *response) {
            NSLog(@"response: %@", [response bodyAsString]);
        };


    }];
}
于 2012-08-21T06:59:00.670 回答
0

查看实例变量baseUrlinputDict. 始终使用属性而不是实例变量,您将永远不会遇到此类问题。

于 2012-08-20T12:52:29.243 回答