我已经开始使用StackMob将Facebook整合到我的应用程序中。我一直在尝试使用StackMob的离线同步,但它似乎坏了。
在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];当用户登录到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);
}];问题是,尽管已经成功地创建了用户,但获取result的结果是一个空数组。当我将缓存策略更改为SMCachePolicyTryCacheElseNetwork时,获取result的结果不是空数组。
为什么用户没有保存在缓存中??另外,我如何告诉StackMob只在缓存中保存一些对象?
非常感谢!
发布于 2013-08-04 16:16:00
这听起来像是一个bug,你可以报告它这里。您可以通过使用每个请求缓存策略来解决这一问题,这样就不必全局设置SMCachePolicyTryCacheElseNetwork。将获取请求更改为:
SMRequestOptions *options = [SMRequestOptions options];
options.cachePolicy = SMCachePolicyTryCacheElseNetwork;
[self.managedObjectContext executeFetchRequest:fetchRequest
returnManagedObjectIDs:NO
successCallbackQueue:dispatch_get_main_queue()
failureCallbackQueue:dispatch_get_main_queue()
options:options
onSuccess:(SMResultsSuccessBlock)successBlock
onFailure:(SMFailureBlock)failureBlock];注意,每个请求缓存策略都需要最新的2.1SDK。
https://stackoverflow.com/questions/18037676
复制相似问题