iOS Documents with UIFileSharingEnabled - iphone

My iPhone app uses a sqlite3 database for storing the data that it generates. This data needs to persist, and I need to make sure the user cannot damage it. I also want to allow the user to export data as text/csv files, these would be shared through iTunes. I plan to put the database in the Library folder, write the CSV files to the Doucments folder, and turn on UIFileSharingEnabled.
Is there anyway I can stop the user from adding files to my apps Documents directory through iTunes?
If not, it is acceptable practice to have my app delete any files that it did not create?

Is there anyway I can stop the user from adding files to my apps Documents directory through iTunes?
No
If not, it is acceptable practice to have my app delete any files that it did not create?
Of course not. Why do you want to do this anyway? If you use the documents directory for exporting only, simply ignore anything that's inside.

Related

Whats the difference between saving content at document directory or temp folder?

I want to save multipel photos in my application, so that application run in background.
So what is the main difference between saving photos in doc dir or temp path.
And suggest me which is best way to save photos
Document Dir
Temp Folder
NSUserDefaults
Thanks in advance
Here is a reference: File System Programming Guide.
Temp folder:
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 it determines they are no longer needed. (The
system may also purge lingering files from this directory when your
app is not running.)
Documents folder:
Use this directory to store critical user documents and app data
files. Critical data is any data that cannot be recreated by your app,
such as user-generated content.
Usually, I put files in temporary folder only when I cache something and I don't care if these files will be deleted. If I want to be sure these files should live long life, I put them to documents folder.
The main difference is the path: <sandbox>/Documents or <sandbox>/tmp.
Some more differences:
The Documents directory can be accessed via iTunes if your app has file sharing enabled.
The contents of the tmp directory is volatile, the OS is free to purge it in order to save space.
About NSUserDefaults: that's something completely different, it's a mechanism which stores app-specific configuration data in property lists, I can't imagine how and/or why you would use it for storing images.

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.

Newsstand App Storage

I have developed one app in which, monthly magazine issues are downloaded and stored inside the app Document directory.
But app have rejected app due to storing of magazine issue in document directory. My magazine file size is around 50 MB.
They mentioned below:
The iOS Data Storage Guidelines indicate that only content that the user creates using your app, e.g., documents, new files, edits, etc., may be stored in the /Documents directory - and backed up by iCloud.
Temporary files used by your app should only be stored in the /tmp directory; please remember to delete the files stored in this location when the user exits the app.
Data that can be recreated but must persist for proper functioning of your app - or because customers expect it to be available for offline use - should be marked with the "do not back up" attribute. For NSURL objects, add the NSURLIsExcludedFromBackupKey attribute to prevent the corresponding file from being backed up. For CFURLRef objects, use the corresponding kCFURLIsExcludedFromBackupKey attribute.
Any help appreciate.
Thanks.
Move your files to the Caches directory and you should be good to go.
I believe that if it is user generated content, there is no problem with storing it on the /Documents folder.
Since it is content that can be downloaded again, you have to set the NSURLIsExcludedFromBackupKey file attribute which prevents it from being backed up to iCloud.
Take a look at this question on setting the attribute: Use NSURLIsExcludedFromBackupKey without crashing on iOS 5.0

Is there a way to save a users data during an iPhone app update?

The users information is stored in a directory inside the apps documents directory. I dont know if I should be trying to copy the documents directory for the old version to the new version or if the update will automatically do this. Or is there another way altogether?
The files inside Documents directory are preserved during an app update.

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?