I want to download a Javascript/Html5 code in zip format and then unzip the code and load the index.html file in webview in iOS.
So where should I save this zip folder on iPhone ? Document Directory or cached Directory ?
All data that can be downloaded again most correct be stored in cached Directory. Files stored in Document folder will be synchronized with iCloud. See link. In your case, I think you need to store in cached.
Hope it helps you.
Better store it in document directory since your file should be available always.In Cache directory,you should store only those files which can be recreated easily. System may delete content of this directory (to free up the disk space) when it is required.
Related
Let's say an app downloads images from web while the user is browsing the app. Let's assume there are virtually unlimited images and a new image is downloaded whenever the user demands one. These images are saved to tmp directory for caching purpose. Once the user closes the app, all the images downloaded are deleted by the app.
Now, as there are unlimited images, what will happen if the user requests next image, the storage is full and the app attempts to save the image to the tmp directory?
Will the previous images be deleted by the iOS automatically to provide the space required for the new images?
OR
Will the iOS start cleaning tmp directory associated with other apps?(If yes, what happens when the storage is full again and such cleaning has already taken place for all the other apps?)
OR
Will the app crash?
If you try and save a image to disk and the disk is full then NSData's
- (BOOL)writeToURL:(NSURL *)aURL
options:(NSDataWritingOptions)mask
error:(NSError **)errorPtr
Will return NO and an error object will be assigned to the errorPtr passed into the method. This error will have a NSFileWriteOutOfSpaceError. This error is very exceptional, and by the time you get it it's safe to say the system will have already notified the user that he is running out of disk space.
Having said that, a lot can be said about cleaning after yourself. If you're not going to use a saved image resource anymore then delete it from the file-system.
Cheers!
tmp/
Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.
The contents of this directory are not backed up by iTunes.
That's the only thing documented. From this I can infer that it won't purge you tmp if your app is running,but it can purge the tmp of other apps which are not running
As #InderKumarRathore says, the docs imply that the system will not delete files from your temp directory when your app is running. The docs also don't promise that the system will delete contents from other apps' temp directories to make space for you.
I would suggest coding defensively: Keep track of the oldest/least recently used files in your temp directory and delete them yourself. Preflight file saves to make sure there is enough space, and display a message to the user if there isn't enough space to save the file(s).
I am working on an app that saves files to the documents directory, and then saves an absolute path for each of those files in an entity using core data. The issue is that each time I rebuild and run my app on my device, the app is saved in a different generated directory, and those file paths are now incorrect. However, my documents directory is still preserved.
I have three questions about this:
If an app is updated on the store, does it then go in a different generated directory, thus invalidating any absolute paths that could be saved in the documents directory?
This is extremely unlikely but is there any way to specify in Xcode to build the app to the same directory the previous build was in?
Is there a way to specify in Xcode that you would like all documents and data wiped with each new build you load on the device?
Thanks everyone!
You said:
"I am working on an app that saves files to the documents directory, and then saves an absolute path for each of those files in an entity using core data."
Don't do that. Ever. The path to your documents directory will be different on different devices, and different if you delete your app and reinstall it. Absolute paths are pretty much guaranteed to fail.
Use paths relative to the sandbox directory in question (documents directory, temp directory, etc)
I developed an Ipad app which download different kind of files, but after a week or some days the downloaded files are removed and the app that open the file can find it anymore.
Could anybody help me, Where should I save downloaded files in my app to avoid that the file came automatically deleted?. IOS usually remove downloaded files after certain time?.
I already read this apple documentation
I know that maybe is not something complicated but I can't figure out why the file is removed If anybody can help me I'll appreciate that.
Put data cache files in the /Library/Caches
directory. Examples of files you should put in this directory include
(but are not limited to) database cache files and downloadable
content, such as that used by magazine, newspaper, and map apps. Your
app should be able to gracefully handle situations where cached data
is deleted by the system to free up disk space.
Most probably you are using caches/temp directory which the system can clear contents of in case of low space. To avoid deletion use Documents Directory.
If you are already storing in documents directory, then the file can appear missing if you are storing its hardcoded path , which can change during app update. Try storing relative path and log the contents of your documents directory to see what files exist.
save the files in your local sqlite db, data core or if you can serialize them with the standard user defaults
I recently had my application rejected, by Apple for:
"Your app has the UIFileSharingEnabled key set to true in the Info.plist, but files and folders not intended for file-sharing are contained within its Documents folder..."
I am storing my application data in the documents directory, images and the core data database. This is a very simple progress, that allows the user to backup and import data. Below are the major steps:
The user can backup the data, which zips the folder.
The user can then use iTunes file sharing to take out the backup.
The user can import, the zip file which overwrites the data in the documents directory.
Has anyone else experienced similar issues? It seems like I am using this correctly.
You should put the zip file in the Documents folder, not any other files. The fact that you also put your core-data files (and some of the other files the user shouldn't see) in the Documents folder is why it was rejected.
You can store any files that the user shouldn't see in another folder such as the Application Support folder.
Since ios5, the file in the NSDocument would be upload to iCloud automatically, if the file in NSDocument is too large Apple would reject the app.
I want to know what path should I store the downloaded file, and what path to store un-completed file (Would not be deleted when application terminate)?
The Caches directory is suitable for files that can be replaced if they were to disappear. In other words, if the file you download can simply be downloaded again if it were to be deleted, then the Caches directory is a good place.
If the downloaded file isn't replaceable and the downloaded file is something that the user initiates as data for the app, then the Documents directory is actually a good place and shouldn't cause rejection.