我已经开始使用 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);
}];
问题是 fetchRequest 的结果是一个空数组,尽管用户已成功创建。当我将缓存策略更改为 SMCachePolicyTryCacheElseNetwork 时,fetchRequest 的结果不是空数组。
为什么用户没有保存在缓存中?另外,我怎样才能告诉 StackMob 只在缓存中保存一些对象?
太感谢了!