Tuesday, May 22, 2012

Error while loading the data from server to core data model using restkit

i am using restkit in my project. i can sucessfully load data using the restkit and can store to data base by manually passing the loaded data to the coredata objects. Later i modified it to the restkit coredata model then i am getting the error like this. when run first time

reason = "The model used to open the store is incompatible with the one used to create the store";

my core data was set correctly and its working fine when i pass the data to keys manually.

i got a solution to delete the app or delete the app data from simulator file,
so i deleated the app from the simulator and again run it.this time i got the this error

 2012-05-18 17:38:45.610 MAW[85942:15203] W restkit.network:RKObjectLoader.m:281 Unable to find parser for MIME Type 'text/html'
2012-05-18 17:38:45.612 MAW[85942:15203] W restkit.network:RKObjectLoader.m:309 Encountered unexpected response with status code: 200 (MIME Type: text/html -> URL: http://api.artworkmanager.com/v1auth?username=anuj.gakhar%40gmail.com&password=1234 -- http://api.artworkmanager.com/v1 -- http://api.artworkmanager.com/v1 -- http://api.artworkmanager.com/v1)
2012-05-18 17:38:45.614 MAW[85942:15203] Encountered an error: Error Domain=org.restkit.RestKit.ErrorDomain Code=4 "The operation couldn't be completed. (org.restkit.RestKit.ErrorDomain error 4.)"

Hear is my code

// Initialize RestKit
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURLString:@"http://api.artworkmanager.com/v1"];
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;

RKManagedObjectStore* objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"MAW.sqlite"];

RKManagedObjectMapping* customerMapping = [RKManagedObjectMapping mappingForClass:[Customer class]inManagedObjectStore:objectStore];
[customerMapping mapKeyPath:@"phone" toAttribute:@"phone"];
[customerMapping mapKeyPath:@"organization" toAttribute:@"organization"];
[customerMapping mapKeyPath:@"siteAdministrator" toAttribute:@"siteAdministrator"];
[customerMapping mapKeyPath:@"customerType" toAttribute:@"customerType"];
[customerMapping mapKeyPath:@"id" toAttribute:@"id"];

RKManagedObjectMapping* articleMapping = [RKManagedObjectMapping mappingForClass:[User class]inManagedObjectStore:objectStore];
[articleMapping mapKeyPath:@"email" toAttribute:@"email"];
[articleMapping mapKeyPath:@"fullname" toAttribute:@"fullname"];
[articleMapping mapKeyPath:@"id" toAttribute:@"id"];

// relationship mapping
[articleMapping mapKeyPath:@"customer" toRelationship:@"customer" withMapping:customerMapping];

[[RKObjectManager sharedManager].mappingProvider addObjectMapping:articleMapping] ;

[self loadData];

my delegate methods

// fetch your mapping
RKObjectMapping *customerMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Customer class]];
//request data
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"auth?password=1234&username=anuj.gakhar@gmail.com/customer" objectMapping:customerMapping delegate:self];
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
RKLogInfo(@"Load collection of: %@", objects);

- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
NSLog(@"Encountered an error: %@", error);

- (void)request:(RKRequest*)request didLoadResponse:
(RKResponse*)response {
if ([request isGET]) {
if ([response isOK]) {
NSLog(@"Retrieved JSON: %@", [response bodyAsString]);
} else if ([request isPOST]) {
if ([response isJSON]) {
NSLog(@"Got a JSON response back from our POST!");

can any one help me how can i solve this. and also suggest me in using restkit. As i am new to iphone feeling little bit difficult to with rest kit. Shall i continue with this or suggest any other alternatives i will go them. if not suggest me a good resorce to follow restkit. now i am going through this restkit in github https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md

I have tried by running the example twiter code provided in the restkit https://github.com/RestKit/RestKit/tree/master/Examples/RKTwitterCoreData . It is also giving the same error, what might be the problem????(either ios / restkit) i have found an issue here https://github.com/RestKit/RestKit/issues/321. any ideas? thank you...

No comments:

Post a Comment