skobbler我可以缓存json数据吗? [英] skobbler can i cache json data?

查看:52
本文介绍了skobbler我可以缓存json数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将skobbler和skmaps用于可离线下载的应用程序,以使用地图的某些区域.我使用的是我在框架包示例中找到的代码,在这种情况下

I'm using skobbler and skmaps for an app that download for offline use some regions of the map. I'm using the code i have found in the example of the framework package, in this case

MapJSONViewController
MapDownloadViewController

我还实现了应用程序委托代码,因此,每次启动应用程序时,它都会下载并解析大约1mb的json

I have implemented also the app delegate code, so every time i start the app, it download and parse a json of about 1mb

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

有可能避免这种行为吗?如果不需要,我不想在每个应用程序初始化中下载1mb的json数据...也许我可以在我的应用程序中下载并包含一个物理地图json文件以拥有一个起始版本?还是这种本地行为"将很快使我的应用程序与过时的json版本一起使用?也许另一种行为是维护带有数据的本地版本,例如每周仅一次重新下载一次……在我看来,这是一个常见的问题,有人能实现便捷的行为吗?

It's possible to avoid this behaviour? I don't want to download 1mb of json data every app init if not necessary... Maybe i can download and include a physic map json file in my app to have a start version ? Or this "local behaviour" will bring my app to work with an outdated json version very soon? Maybe another behaviour is to maintain a local version with a data and redownload it only once a week for example... It seems at me a common problem, there's someone how achive a convenient behaviour?

推荐答案

是的,您可以在应用程序&从磁盘读取它.

Yes, you can include the json file in your app & read it from disk.

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

In the XMLParser.m replace the code in downloadAndParseJson with:

- (void)downloadAndParseJSON
{
    [self parseJSON];

    NSString *libraryFolderPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSLog(@"%@",libraryFolderPath);
}

并使用以下方法解析JSON:

and parseJSON with:

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

此处,您可以找到一个修改后的演示项目,其内容如下:资源中的Maps.json文件(资源文件夹中包含.json文件).

Here you can find a modified demo project that reads the Maps.json file from resources (the .json file is included in the resources folder).

这篇关于skobbler我可以缓存json数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆