Storing additional game content, where can we?!

Hey guys,

So Corona just released a ZIP plugin for Corona SDK, this is AWESOME news.  I was planning to use the TAR module to package additional content together for my app but now I can use a zip file.

My major concern however, is the following:  I have read in a few places now that Apple does not approve of us storing downloaded content in the “System.DocumentsDirectory” because it gets backed up via iCloud.

Instead Rob Miracle has suggested that these things should be stored in the “System.Caches” directory.

In my case, the user is downloading a whole new chunk of content for the app, this includes images, audio, and some JSON files.  It will be about 20mb big of a download.

In my mind, it seems silly to store this kind of data in the “Caches” directory seeing as it could be deleted at any time.  How are we supposed to build a stable and reliable app if every other day the user finds out that the new content they downloaded is now missing?

Is there something I am missing here? How are we supposed to handle downloading and storing game content without Apple getting mad about it?

Any thoughts and comments are appreciated.

Hi @rxmarccall,

You can probably solve this by “voiding” specific items in the Documents directory from being sent to iCloud. This is done with the native.setSync() API, documented here:

http://docs.coronalabs.com/api/library/native/setSync.html

Hope this helps,

Brent

Oh cool I’ll have to take a look at that.

I was reading a blog post by Rob Miracle that is a year old in which he says " Corona SDK currently does not give us an option to turn off those backups." (talking about iCloud)

Hopefully what you posted is the solution to this!

Hmmm, do you have a link to that blog post? I’ll correct that line… :slight_smile:

Brent

Well I think this is his personal blog possibly, again its old so I doubt many people come across it.

Here is the link: http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

And the zip blog post he read is here, maybe you could add a note about that feature on the blog post: http://coronalabs.com/blog/2013/05/21/tutorial-using-zip-plugin/#comment-27589

Also wondering Brent, do you know if Corona has a way to handle if a users device runs out of memory when downloading a file?  I am wondering for example if my user is downloading new content, and their device becomes full, will Corona throw a message of any kind? or will the User just get a half built corrupted file I wonder?

Yea, that blog post is kind of old, and the setSync was added later.

Hi @rxmarccall,

You can probably solve this by “voiding” specific items in the Documents directory from being sent to iCloud. This is done with the native.setSync() API, documented here:

http://docs.coronalabs.com/api/library/native/setSync.html

Hope this helps,

Brent

Oh cool I’ll have to take a look at that.

I was reading a blog post by Rob Miracle that is a year old in which he says " Corona SDK currently does not give us an option to turn off those backups." (talking about iCloud)

Hopefully what you posted is the solution to this!

Hmmm, do you have a link to that blog post? I’ll correct that line… :slight_smile:

Brent

Well I think this is his personal blog possibly, again its old so I doubt many people come across it.

Here is the link: http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

And the zip blog post he read is here, maybe you could add a note about that feature on the blog post: http://coronalabs.com/blog/2013/05/21/tutorial-using-zip-plugin/#comment-27589

Also wondering Brent, do you know if Corona has a way to handle if a users device runs out of memory when downloading a file?  I am wondering for example if my user is downloading new content, and their device becomes full, will Corona throw a message of any kind? or will the User just get a half built corrupted file I wonder?

Yea, that blog post is kind of old, and the setSync was added later.

Can the setSync be applied to an entire directory? This way I can download all the content and unzip to one directory and make sure the setSync is set to false at the directory level.

I wonder the same thing.  From looking at the documentation I thought maybe you could just call native.setSync( { iCloudBackup = false } ) without having a “file name” or “directory” included in the call that it would disable the entire document directory.

Can anyone confirm this?  I’ll try when I get home, but I just got to work so it will be a while.

Hello @shivapp, @rxmarccall,

At this point, native.setSync() works on a per-file basis. It’s not a widely-used API, and the assumption is that most developers will want to only exclude certain (large) files from iCloud backup, not an entire directory. We might reevaluate this in the future, but for now, the workaround would be to loop through the entire directory using LFS to gather up the files within, and apply the non-sync to all of them.

Best regards,

Brent

Dang that is a pain. Well thanks for letting us know at least.  @shivapp, I’ll try and post code for looping through the documents directory and setting it to not sync.

For now this is what I am doing. I am yet to test it but I am hoping it would work. I download a zip file for my content and while unzipping it I am setting the sync on it.

local function zipListener( event )

    if(event.isError) then

        print( “Unzip error” )

    else

        print( “event details:” … event.name … " " … event.type)

        if(event.response and type(event.response) == “table”) then

            for i = 1, #event.response do

                print(event.response[i])

                if(system.getInfo(“platformName”) == “iPhone OS”) then

                    native.setSync(event.response[i], {iCloudBackup = false})

                end

            end    

        end

    end

end

Woah sweet, so you are able to reference each file as the zip file is getting unzipped?

I am not sure. I will test and let you know in a day or so.

Sounds good I’ll try it as well, thanks.

On a similar note. Brent, would you know when there would be password based archiving in the zip plugin? For allowing users to download content after doing an in-app purchase this would be very helpful so malicious users can’t get our sprites or images.