iOS sort files in folder by date added - iphone

My app downloads files from the internet.
App stores them in Documents folder .
App uses iTunes Sharing feature, and user can store files in Documents folder through iTunes (when my application is launched and when my app is not launched).
In one of tableviews in my app I want to present files from Documents directory sorted by Date added (date, when files were added to Documents directory).
Is there any file attribute like "Date Added" on iOS?
How can I retrieve it?
I searched for this, but I cannot found an answer for now.
I think I can save the date for downloaded files and files that were added through iTunes when my app was launched, using DirectoryWatcher.
But I don't know how can I get the "date added" for files that were stored in Documents through iTunes when my app was not launched.
How can I do this?
I know that there is Arrange by Date Added in Finder on Mac OS 10.7. How they do it?
Thank you.

Yes you can use NSFileManager to do this, you can give it a file path to request a dictionary of attributes, one being the modification date
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDictionary/fileModificationDate

I found that file does not contain Date Added in its attributes.
After copying files through iTunes Connect from mac to app creation date and modification date remains unchanged (as they were on the mac).
Also I found that Finder on Mac uses external sqlite database ~/Library/Preferences/com.apple.dock.db for storing Date Added attribute.
So for my needs I have decided to use some kind of external database for storing "date added" value.
I think I will use NSUserDefaults, and I will use filename and inode number as a key.

Related

On App update custom plist file will get updated or do we need to do some thing?

I have an app in appstore now im going to push out an update of app, Im having a custom Plist file with set of values in my application bundle, and these values are been modified from the version which is in production and in addition even more key value pairs are added in to this file.
Now my doubt is on updating this app to appStore will the update process automatically overrides(updates) my new plist file on top of existing one or do we need to do some work around like how we do for database changes like coredata migration and all?
As explained here: iOS App Programming Guide, this is what happens when you update an app:
Files Saved During App Updates
When a user downloads an app update,
iTunes installs the update in a new app directory. It then moves the
user’s data files from the old installation over to the new app
directory before deleting the old installation. Files in the following
directories are guaranteed to be preserved during the update process:
Application_Home/Documents
Application_Home/Library
Although files
in other user directories may also be moved over, you should not rely
on them being present after an update.
This means that all the resources that were in your bundle will be "lost" and you will have the new ones from your new bundle. If you were using this plist file for read only purposes this won't be a problem, if you were saving some user preference on this file, i'm afraid that these user information will be lost. You should save this kind of data in the documents directory, always!
When the update is deployed it will overwrite existing plist files.
When you update your app on App store it replaces new binary with old binary. So with binary it also replaces your plist too. So don't worry about that, just be aware that your info in app store details and details in plist should be same otherwise it will not take your binary file for app version update.

iOS - Allow user to download file from documents directory but not to upload file using iTunes

Here is a situation I have a data file in document directory which is being updated in the application every now and then. So I want to save it to my desktop using iTunes. But I don't want that the file should be uploaded back to my application. i.e. I want that user can download the file but can not upload any.
I was thinking to have the data file on some other location like Library and put a button on application settings saying "Prepare backup" that will copy that data file in Document directory, from where user can download it. If user uploads any thing it won't make any difference as my current file is in Library directory.
This is just a thought,
can anyone suggest me other way or the above way is good to go?
Edit: I just need that after the successful export user can view the data file (may be later) without support of the application.
You can't.
But what you can do is check (using an timer every 10 seconds) if a new file is added to the documents directory and then delete it programmatically.
But this ofcourse doesn't disable the replacement of files.

Is it possible to limit iOS file sharing functionality to a subfolder in the documents directory?

My image editing app is saving some important data in the documents directory. In a tutorial I was reading this:
iTunes will then display anything you
save to the Documents directory in
your app to the user, when they go to
the “Apps” page in iTunes and scroll
to the bottom:
I have a subfolder called userImages and it would be clever to restrict file sharing only to that folder and not to everything in documents. Otherwise the user would accidently (or on purpose) mess around with files that the app depends on to work properly. This would be bad.
Is there a way to restrict it to a subdirectory in documents?
No, what you should do instead is store anything you do not want users seeing in the "Library" directory for the app. Check here for a list of places you can store data:
How can I get a writable path on the iPhone?

Shipping Documents Items with an iPhone App

My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?
EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.
-Ash
Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.
A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.
You include it as a file in the Resources folder of your application.

Replace existing XML file within iPhone app

I have an .xml file that is going to be shipped within my app.
This file contains values that are read from it and saved as an array when the app launches.
Each time the app is run, I want to check with the server if there is an internet connection. If so, I want to get the newest version of the .xml file from the server and replace the one that I currently have saved in my app (this way, the next time the user logs in and doesn't have internet access, he/she will be able to use the old (yet most up to date) data).
What is the best way to do this?
Thanks,
The best way to probably do this is to copy the XML file from the app bundle to a location in the app's sandbox, e.g. the Documents folder. Thereafter you can update the XML content as necessary with newer data from the server. The copy is necessary to allow you to write to the file, since you cannot change the content of your app's bundle because it is signed.
Alternatively, if the data is simple enough, you can just save it to user defaults on first launch and change the defaults on subsequent updates
I might skip the XML altogether, unless it contains a baseline of default settings, and just sync user defaults over the Internet. You can't modify files in the bundle, so your only option would be to copy over a "default-settings" XML file to the application's Documents folder to make it editable.