我将 skobbler 和 skmaps 用于一个应用程序,该应用程序可以下载以供离线使用 map 的某些区域。我正在使用我在框架包示例中找到的代码,在这种情况下
MapJSONViewController
MapDownloadViewController
我还实现了应用程序委托(delegate)代码,所以每次我启动应用程序时,它都会下载并解析大约 1mb 的 json
- (void)mapsVersioningManager:(SKMapsVersioningManager *)versioningManager loadedWithMapVersion:(NSString *)currentMapVersion
{
[[XMLParser sharedInstance] downloadAndParseJSON];
}
有可能避免这种行为吗?如果没有必要,我不想在每个应用程序初始化时都下载 1mb 的 json 数据...也许我可以下载物理 map json 文件并将其包含在我的应用程序中以获得起始版本?或者这种“本地行为”将使我的应用程序很快就可以使用过时的 json 版本?也许另一种行为是维护一个带有数据的本地版本,例如每周只重新下载一次……在我看来这是一个常见的问题,有人如何实现方便的行为?
最佳答案
是的,您可以在您的应用中包含 json 文件并从磁盘读取它。
在 XMLParser.m 中,将 downloadAndParseJson 中的代码替换为:
- (void)downloadAndParseJSON
{
[self parseJSON];
NSString *libraryFolderPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"%@",libraryFolderPath);
}
和解析JSON:
- (void)parseJSON
{
NSString *jsonString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Maps" ofType:@"json"] encoding:NSUTF8StringEncoding error:nil];
SKTMapsObject *skMaps = [SKTMapsObject convertFromJSON:jsonString];
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate setSkMapsObject:skMaps];
self.isParsingFinished = YES;
[[NSNotificationCenter defaultCenter]postNotificationName:kParsingFinishedNotificationName object:nil];
}
Here你可以找到一个修改过的演示项目,它从资源中读取 Maps.json 文件(.json 文件包含在资源文件夹中)。
关于ios - skobbler 我可以缓存 json 数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765992/