Error with loading objects from a Response(RestKit)
Your API returns HTTP Error 401 Unauthorized. Does your backend require a HTTP authentication? If so, supply the correct credentials to the RKClient
:
[[RKClient sharedClient] setUsername:myUsername];[[RKClient sharedClient] setPassword:myPassword];
edit:
I believe you have some fundamental problems in setting up the RestKit. Consider the following example.
//in your appdelegateRKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://localhost:8080/activiti-rest/service"]; [[RKClient sharedClient] setUsername:@"kermit"];[RKClient sharedClient] setPassword:@"kermit"];// don't forget to create your mapping hereRKObjectMapping *dataMapping = [RKObjectMapping mappingForClass:[Data class]];[dataMapping mapKeyPath:@"myKeyPath" toAttribute:@"myAttr"];[[manager mappingProvider] addObjectMapping: dataMapping];
then, you can do just this.
-(void)loadData{ // fetch your mapping [RKObjectMapping *mapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Data class]]; //request data [[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/process-definitions?start=0&size=10&sort=id&order=asc" objectMapping:mapping delegate:self];}
Firstly, you need to do the setup (RKClient
, mappings and RKObjectManager
) - you do it just once. They are singletons, so the settings are kept. I found that best place to do this is the AppDelegate - feel free to experiment, but be sure to make the setup before you do any requests.
When you are about to do any requests just use your [[RKObjectManager sharedManager]
singleton to load the actual objects.
Also, i recommend you reading some documentation, eg. the Object Mapping guide