Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Storing additional game content, where can we?!
Started by rxmarccall May 23 2013 10:26 AM

- - - - -
21 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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.



[TOPIC: post.html]
#2

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,528 posts
  • Jedi

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



[TOPIC: post.html]
#3

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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!



[TOPIC: post.html]
#4

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,528 posts
  • Jedi

Hmmm, do you have a link to that blog post? I'll correct that line... :)

 

Brent



[TOPIC: post.html]
#5

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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?



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Corona Staff
  • 10,051 posts
  • Jedi

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



[TOPIC: post.html]
#7

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Starter
  • PipPip
  • 28 posts
  • Member

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.



[TOPIC: post.html]
#8

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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.



[TOPIC: post.html]
#9

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,528 posts
  • Jedi

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



[TOPIC: post.html]
#10

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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.



[TOPIC: post.html]
#11

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Starter
  • PipPip
  • 28 posts
  • Member

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



[TOPIC: post.html]
#12

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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



[TOPIC: post.html]
#13

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Starter
  • PipPip
  • 28 posts
  • Member

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



[TOPIC: post.html]
#14

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

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



[TOPIC: post.html]
#15

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Starter
  • PipPip
  • 28 posts
  • Member

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.



[TOPIC: post.html]
#16

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

+1.  Probably the best you can do for now is keep your zip on a FTP server.  Thats all I've been able to find a get set up.  On Android though I assume people will always be able to get at assets pretty easily.



[TOPIC: post.html]
#17

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

@shivapp

Did your code that you shared above for setting "setsync" to false while a zip file is extracted end up working for you?



[TOPIC: post.html]
#18

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Starter
  • PipPip
  • 28 posts
  • Member

Yes I am able to reference each file in that for loop and can set the sync to false.



[TOPIC: post.html]
#19

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Starter
  • PipPipPipPipPipPip
  • 751 posts
  • Jedi

Awesome, thanks for figuring that out!



[TOPIC: post.html]
#20

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,741 posts
  • Jedi

Hi, just following your trails on this old thread. Wondering if any of the apps using "System.DocumentsDirectory" for downloaded and unzipped content got rejected by Apple. A short update (all ok or rejected by Apple etc) would be very appreciated. Thanks



[TOPIC: post.html]
#21

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Corona Staff
  • 10,051 posts
  • Jedi

I know people have been rejected for storing too much in system.DocumentsDirectory.  When the added the system.CachesDirectory, they were quite clear that if it can be downloaded, it needs to go there.  When they added iCloud backups, they started looking even closer at what's being stored because iCloud storage is limited.

 

If you need to keep things in system.DocumentsDirectory and its more than a few kbytes in size, you probably should set the flag that tells iOS not to back it up.



[TOPIC: post.html]
#22

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,741 posts
  • Jedi

If you need to keep things in system.DocumentsDirectory and its more than a few kbytes in size, you probably should set the flag that tells iOS not to back it up.

 

Absolutely. I will use the method shared above by @shivapp and will turn off synch. I was just wondering whether @shivapp or @rxmarccall (or others) had any trouble using this approach. Thanks for your feedback.




[topic_controls]
[/topic_controls]