Restkit Objective-C: mail request only works once

I use Restkit to communicate with Drupal CMS. When I send the first request, everything works fine: I get the correct JSON-string -> awesome. Here is what the console says:

2011-06-24 23: 00: 48.344 MyApp [1399: 207] Sending a POST request to the URL http://mysite.com/myproject/services/rest/service_views/get.json . HTTP Body: view_name = viewsname

If the application tries to send the same request again, nothing happens. None of the delegate method methods. The console says:

2011-06-24 23: 03: 40.224 MyApp [1399: 207] Submitting a GET request to the URL http://www.mysite.com/myproject/services/rest/service_views/get.json . HTTP body:

I do all the Restkit things in a special class (singleton), which I save as an instance variable of my view controller. In the init function of this class, I do this:

RKObjectManager* objectManager = [RKObjectManager
objectManagerWithBaseURL:kBaseURLKey];

In my view controller I call a function - (void)pollForNewData that does the following:

RKObjectLoader* objectLoader = [[RKObjectManager sharedManager] loadObjectsAtResourcePath: kRessourceKey objectClass:[RKNotification class] delegate:self]; 
objectLoader.method = RKRequestMethodPOST;
objectLoader.params = [NSDictionary dictionaryWithKeysAndObjects: @"view_name", @"viewsname", nil];
[objectLoader send];

Can someone help me? Should I do something special after the first answer came? Is it possible to cancel the request (if the current view remains)?

+5
source share
1 answer

The current RestKit source (~ 0.9.2 +) does not seem to have loadObjectsAtResourcePath: objectClass: delegate: method.

You can use something like this:

// It for logging in Drupal user resource with RestKit.
// You can change the user bits to your need.

RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKObjectMapping *currentUserMapping = [objectManager.mappingProvider objectMappingForKeyPath:@"currentUser"];

RKObjectLoader *objectLoader = [objectManager objectLoaderWithResourcePath:@"user/login" delegate:self];
objectLoader.method = RKRequestMethodPOST;
objectLoader.objectMapping = currentUserMapping;
objectLoader.params = [NSDictionary dictionaryWithObjectsAndKeys:
                       @"testuser", @"username",
                       @"testpass", @"password",
                       nil];
[objectLoader send];

Hope this helps.

+6
source

All Articles