I have a project which you can imagine is like the Facebook app and I'm having trouble grasping how to organize it with RestKit and handle tokens since I'm a RestKit beginner.
This is what I got so far:
- Core Data NSManagedObject classes, for each of them I added a category called REST that has functions to provide RKObjectMapping and RKRouteSet
- custom RKObjectManager subclass which handles setting up headers, MIME types, setting authorization headers and Core Data stores
- RKObjectRequestOperation subclass
If you have organizational advice shoot, but my main question is how do I implement automatic token refreshing after recieving a 401 HTTP status code and firing the failed request again with a fresh token?
I started by overriding the metod in my RKObjectRequestOperation subclass:
- (void)setCompletionBlockWithSuccess:(void ( ^ ) ( RKObjectRequestOperation *operation , RKMappingResult *mappingResult ))success
failure:(void ( ^ ) ( RKObjectRequestOperation *operation , NSError *error ))failure
So now I can intercept a 401 response, but now I have to make another call to refresh the token and then re-enqueue the failed operation with a fresh token, please advise how to do that.