Results 1 to 7 of 7

Thread: Avoid offline maps from getting deleted when free disk space is low

  1. #1
    Etablierter skobbler
    Join Date
    15.03.2017
    Posts
    11

    Avoid offline maps from getting deleted when free disk space is low

    We got reports from iOS users that their offline maps got deleted when they only had a certain amount of disk space left. From our perspective, this is not the desired behavior because the user actively chose to install the maps in the first place.

    Apparently, the offline maps are stored along with other data in the systems caches directory. We would like to avoid this. The optimal solution would be if the offline maps directory would be configurable independently from the caches directory. However, since this would require an update of the SDK, we came up with a different solution to work around this issue (while still keeping real cached data in the caches directory).

    We would like to ask you to assess the steps outlined below and let us know if you see any inherent problem with this solution. You may even have an idea, how to solve this in a more robust way. Your feedback would be well appreciated. Thanks in advance.

    * Change `SKMapsInitSettings.cachesPath` to a persistent directory (e.g. the documents directory)
    * For each non-map-package folder, create a symlink into the caches directory
    Last edited by cobi; 02.11.2017 at 11:26.

  2. #2
    Erfahrener skobbler
    Join Date
    12.09.2016
    Posts
    112
    Hello,
    Please let us know for which OS version you get this behaviour, or this happens for all iOS OSs?
    I’m assuming the maps version is 20170626 and the SDK is 3.0.3, if so please confirm, and we can start looking into this.

  3. #3
    Etablierter skobbler
    Join Date
    15.03.2017
    Posts
    11
    The detailed report we got was from a user with iOS 11.0.1 installed (from others we just got casual hints that their maps disappeared), but I guess this should happen on all iOS versions.

    According to your documentation (verrified that) the files are stored in "\Library\Caches\maps". Apples documentation says:
    * Location of discardable cache files (Library/Caches). (https://developer.apple.com/document...achesdirectory)
    * Use the Caches directory [...] for cached data files or any files that your app can re-create easily. (https://developer.apple.com/library/...10672-CH3-SW11)

    A better place would probably be the NSApplicationSupportDirectory:
    * Use the Application Support directory [...] for resource and data files that your app creates and manages for the user. You might use this directory to store app state information, computed or downloaded data, or even user created data that you manage on behalf of the user. (https://developer.apple.com/library/...10672-CH3-SW11)

    Yes, SDK 3.0.3 and map version 20170626.

  4. #4
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    Hi Cobi,

    I've worked around this by changing the cachesPath property during initailization of the framework. Be aware that you'll have to move already present offline maps on a users device. This is how I did it:

    Code:
           let initSettings: SKMapsInitSettings = SKMapsInitSettings()
     
            let mapsFolderInDocs = localFolder.documents.appendingPathComponent("maps", isDirectory: true)
            if !FileManager.default.fileExists(atPath: mapsFolderInDocs.path) {
                let oldMapsFolder = localFolder.caches.appendingPathComponent("maps", isDirectory: true)
                if FileManager.default.fileExists(atPath: oldMapsFolder.path) {
                    // maps exists in library folder. Moving to documents folder
                    do {
                        try FileManager.default.moveItem(at: oldMapsFolder, to: mapsFolderInDocs)
                    }
                    catch {
                        print("moving of maps folder failed")
                        print(error)
                    }
                }
                else {
                    // maps did not exist in library folder. Creating maps folder in documents folder
                    do {
                        try FileManager.default.createDirectory(at: mapsFolderInDocs, withIntermediateDirectories: false, attributes: nil)
                    }
                    catch {
                        print("creation of maps folder failed")
                        print(error)
                    }
    
                }
            }
            
            initSettings.cachesPath = mapsFolderInDocs.path
            SKMapsService.sharedInstance().initializeSKMaps(withAPIKey: SKMapsAPIKey, settings: initSettings)

  5. #5
    Etablierter skobbler
    Join Date
    15.03.2017
    Posts
    11
    Hi guidove,

    thanks for your reply and the example code. I guess we'll just add something similar to the next release. Just be aware of one thing I mentioned above: this way also real cached data that is downloaded by the library on the fly cannot be removed by the system if necessary. That's the reason I want to try to link the respective folders back to the system caches directory.

    Best regards

  6. #6
    Erfahrener skobbler
    Join Date
    12.09.2016
    Posts
    112
    Hello,

    I've received the following feedback from our dev team in regards to this issue:

    The amount of data that Apple allows us to store in /Documents directory is 5MB.

    "Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud. Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory." ( https://developer.apple.com/icloud/d...age/index.html )

    The users can change the path where the map files are stored from the SKMapsInitSettings class but they will do so at their own risk.

  7. #7
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    Quote Originally Posted by adrian.bortas View Post
    Hello,
    The amount of data that Apple allows us to store in /Documents directory is 5MB.
    Do you have a source for this 5MB limit? I tried to find some documentation on this but have not been able to find it. Also, I have not find this to be the limit. If there is a limit, it seems to be much much higher. I've been using my above workaround for quite some time now. Offline map packages are stored in the documents folder for all my users now and I have users with many offline maps, some of them Gigabytes of offline maps on their device. None of them have given me feedback to indicate there is a limit (other then their total device storage limitation obviously).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •