I have started to integrate Facebook in my app using StackMob. I've been trying to use StackMob's offline sync, but it just seems broken.
In didFinishLaunchingWithOptions:
SM_CACHE_ENABLED = YES;
SMClient *client = [[SMClient alloc] initWithAPIVersion:@"0" publicKey:@"cc5f57c8-4a5d-424d-a3e1-0594c675cad8"];
SMCoreDataStore *coreDataStore = [client coreDataStoreWithManagedObjectModel:self.managedObjectModel];
coreDataStore.cachePolicy = SMCachePolicyTryCacheOnly;
_managedObjectContext = [coreDataStore contextForCurrentThread];
When a user logs in with Facebook:
[[SMClient defaultClient] loginWithFacebookToken:FBSession.activeSession.accessTokenData.accessToken createUserIfNeeded:YES usernameForCreate:nil onSuccess:^(NSDictionary *result) {
NSLog(@"Logged in with StackMob!");
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"User"];
[self.managedObjectContext executeFetchRequest:fetchRequest returnManagedObjectIDs:NO onSuccess:^(NSArray *results) {
NSLog(@"users: %@",results);
} onFailure:^(NSError *error) {
NSLog(@"error: %@",error);
}];
} onFailure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
The problem is that the fetchRequest's result is an empty array, although the user has been created successfully. When I change my cache policy to SMCachePolicyTryCacheElseNetwork, the fetchRequest's result is not an empty array.
Why isn't the user saved in the cache?? Also, how can I tell StackMob to save some objects in the cache only?
Thank you so much!