我有一个应用程序,有离线地图的大文件下载。它最初被拒绝,因为它将地图存储在文档中。根据这一点,地图需要存储在缓存中。
https://developer.apple.com/icloud/documentation/data-storage/
问题是,每次更新应用程序时,所有的地图都会被删除。这确实激怒了人们,并导致他们停止使用该应用程序,并给它糟糕的评论。
从本质上说,这个应用程序是由那些希望依赖于可用的离线地图的旅行者使用的,他们可能没有快速的互联网连接,也没有廉价的数据计划,每次更新都要重新加载数百兆字节的数据。
是否可以将地图存储在文档中,并将其标记为不在备份中的标记?
是否有另一种方法在更新之间持久化映射?
发布于 2014-05-03 11:56:56
这就是对我有用的东西。基本上,将映射放在应用程序支持中,并将它们标记为不备份。
- (NSURL *) getApplicationSupportUrl {
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *urls = [fm URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
NSURL *url = [urls objectAtIndex:0];
url = [url URLByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier] isDirectory:YES];
return url;
}
- (NSURL *) getMapDirectory:(int)cityid {
NSURL *url = [self getApplicationSupportUrl];
url = [url URLByAppendingPathComponent:[NSString stringWithFormat:@"map%d",cityid] isDirectory:YES];
return url;
}
- (BOOL) excludeDirectoryFromBackup:(NSURL *)url {
NSError *error = nil;
BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return success;
}
// in the app
NSRUL *mapurl = [self getMapDirectory:123];
// download maps tiles to mapurl
[self excludeDirectoryFromBackup:mapurl];发布于 2014-04-19 03:02:27
对于这种类型的长期存储,您应该使用/Library/Caches目录。获取此值的代码:
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
directory = [directory stringByAppendingString:@"/Caches"];我很肯定这个目录的内容会通过应用程序更新来保存。然而,如果用户删除应用程序,数据将被删除。
https://stackoverflow.com/questions/23165221
复制相似问题