Question

I have an app that has offline maps in large files which are downloaded. It was initially rejected because it stored the maps in documents. According to this, the maps need to be stored in caches.

https://developer.apple.com/icloud/documentation/data-storage/

The problem is that every time the app is updated, all the maps are removed. This really pisses people off and causes them to stop using the app and give it bad reviews.

By its nature, this app is used by travelers who want to depend on the offline maps being available and who may not have fast internet connections or cheap data plans to reload hundreds of megabytes of data with every update.

Would it be possible to store the maps in documents and flag them to be excluded from backup are described here?

https://developer.apple.com/library/ios/qa/qa1719/_index.html

Is there another way to persist the maps between updates?

Was it helpful?

Solution 2

Here is what worked for me. Basically put the maps in application support and flag them not to be backed up.

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

OTHER TIPS

You should use the /Library/Caches directory for this type of long term storage. Code to get this value:

NSString *directory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
directory = [directory stringByAppendingString:@"/Caches"];

I'm pretty sure the contents of this directory will be preserved through app updates. However, if the user deletes the app, the data will be deleted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top