我使用Parse.com作为后端写在iOS应用内广告。
在- (PFQuery)queryForTable
我的方法PFQueryTableViewController
我取回一组从解析数据,但我不能为了支持功能时,该设备目前处于脱机缓存此查询。
该方法看起来如下:
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query whereKey:@"city" equalTo:[[NSUserDefaults standardUserDefaults] objectForKey:@"city"]];
// userMode is active when a user is logged in and is about to edit coins
if (self.userModeActive) {
[query whereKey:self.textKey equalTo:self.user[@"location"]];
}
// dateFilter is active when view is pushed from an event
if (self.dateFilterActive) {
[self createDateRangeForFilter];
[query whereKey:@"date" greaterThan:[[self createDateRangeForFilter] objectAtIndex:0]];
[query whereKey:@"date" lessThan:[[self createDateRangeForFilter] objectAtIndex:1]];
} else {
// Add a negative time interval to take care of coins when it's after midnight
[query whereKey:@"date" greaterThanOrEqualTo:[[NSDate date] dateByAddingTimeInterval:-(60 * 60 * 6)]];
[query orderByAscending:self.dateKey];
}
// locationFilter is active when view is pushed from a location profile
if (self.locationFilterActive) {
[query whereKey:@"location" equalTo:self.locationToFilter];
}
// If no objects are loaded in memory, look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
if ([query hasCachedResult]) {
NSLog(@"hasCache");
} else {
NSLog(@"chache empty");
}
return query;
}
[query hasCachedResults]
总是返回在这种情况下错误的。
在另一类,我做的是几乎完全一样的查询(在不同的解析级),它会自动缓存。 唯一不同的是,这等查询包含PFFiles
。
这可能是一个愚蠢的问题,但我坚持了好几天了。
感谢您的帮助,让我知道,如果我可以给你更多的信息。