skobbler我可以cachingjson数据?

我正在使用skobbler和skmaps来下载离线使用地图某些区域的应用程序。 在这种情况下,我使用框架包的示例中find的代码

MapJSONViewController MapDownloadViewController 

我也实现了应用程序委托代码,所以每次启动应用程序时,它都会下载并parsing约1mb的json

 - (void)mapsVersioningManager:(SKMapsVersioningManager *)versioningManager loadedWithMapVersion:(NSString *)currentMapVersion { [[XMLParser sharedInstance] downloadAndParseJSON]; } 

有可能避免这种行为? 我不想下载1MB的json数据每个应用程序初始化,如果没有必要…也许我可以下载和包括一个物理地图json文件在我的应用程序有一个启动版本? 或者这个“本地行为”会让我的应用程序很快与过时的json版本一起工作? 也许另一种行为是用数据维护一个本地版本,例如每周仅重新下载一次……在我看来,这是一个常见的问题,有一个人如何实现一个方便的行为?

是的,你可以在你的应用程序中包含json文件并从磁盘读取它。

在XMLParser.m中,将downloadAndParseJson中的代码replace为:

 - (void)downloadAndParseJSON { [self parseJSON]; NSString *libraryFolderPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSLog(@"%@",libraryFolderPath); } 

和parseJSON与:

 - (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]; } 

在这里您可以find一个修改的演示项目,从资源中读取Maps.json文件(.json文件包含在资源文件夹中)。