ios开发怎么从沙盒中取出大量的数据而不卡
1个回答
展开全部
从沙盒中取数据是需要异步处理的,跟从数据库和后台接口取数据一样。必须采用异步处理,不能直接在主线程中取数据。例如下面的沙盒操作。
[self showProgressWithView:self.view animated:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [self libCachePath];
// NSString *filePath = [NSString stringWithFormat:@"%@/%@.zip", docDirPath , [name stringFromMD5]];
NSFileManager* fileManager=[NSFileManager defaultManager];
/**删除zip文件*/
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:docDirPath];
for (NSString *fileName in enumerator) {
[[NSFileManager defaultManager] removeItemAtPath:[docDirPath stringByAppendingPathComponent:fileName] error:nil];
}
[fileManager removeItemAtPath:path error:nil];
[DBDaoHelper createAllTable];
dispatch_async(dispatch_get_main_queue(), ^{
[self hideProgress:self.view animated:YES];
});
[self showProgressWithView:self.view animated:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [self libCachePath];
// NSString *filePath = [NSString stringWithFormat:@"%@/%@.zip", docDirPath , [name stringFromMD5]];
NSFileManager* fileManager=[NSFileManager defaultManager];
/**删除zip文件*/
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:docDirPath];
for (NSString *fileName in enumerator) {
[[NSFileManager defaultManager] removeItemAtPath:[docDirPath stringByAppendingPathComponent:fileName] error:nil];
}
[fileManager removeItemAtPath:path error:nil];
[DBDaoHelper createAllTable];
dispatch_async(dispatch_get_main_queue(), ^{
[self hideProgress:self.view animated:YES];
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询