How to save my data in iOS document folder? - ios

My application need to save data to my local database. The reason why I want to save it to document folder is I want the data shared by all devices with the same iCloud account. What I normally do is to copy the empty database from my Bundle into my document folder the first time when the app launch. But I'm not very sure it will be rejected by Apple or not? (Because one of my app which preloading a database into document folder was rejected.) Do you have better strategy? (I know I can save the data into library folder. But the data will not be synchronized then.)
Thanks.

Related

iOS App Submission Rejection

When i submit my iOS app i got following rejection issues from apple.
On launch and content download, your app stores 13.14MB on the user's iCloud, which does not comply with the iOS Data Storage Guidelines.
Next Steps
Please verify that only the content that the user creates using your app, e.g., documents, new files, edits, etc. is backed up by iCloud as required by the iOS Data Storage Guidelines. Also, check that any temporary files used by your app are only stored in the /tmp directory; please remember to remove or delete the files stored in this location when it is determined they are no longer needed.
Data that can be recreated but must persist for proper functioning of your app - or because users 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 kCRUFLIsExcludedFromBackupKey attribute.
Your App stores data in the users iCloud. This is only alowed to a certain degree.
The 13,14 MB your app stores to the cloud is just too much.
I never submitted an app to Apple, but the error message is clear and defined.
Take a look on your app and what it does store in the iCloud. Reduce the size or just dont write to iCloud.
Hope it helps...
*edit
Why would one write to the iCloud anyways? Just write on the phone memory.
Do you call a web service on App launch which stores data in the App's documents directory? Or do you store some other data in the App's documents directory?
By default all the data in the App's documents directory is synced to iCloud. So any data that can be recreated later (unlike session data) must not be stored on the documents directory.
So instead save data in the App's Temp directory.
To do that have a look at this- How to save images and recoded files in temp directory?
Another option is you have is How to use addSkipBackupAttributeToItemAtURL API?

Save user defaults to iCloud

I don't have any important data in my app. But when i read this tutorial i have a few questions ?
Only documents and other data that is user-generated, or that cannot
otherwise be recreated by your application, should be stored in the
/Documents directory and will be automatically
backed up by iCloud.
Do i need to save UserDefaults to iCloud ? And will my app approve if i don't use iCloud ?
And if i need can you show me how to save user default settings ? Because i found only tutorials how to save data from database.
You misunderstand what that is saying.
When a user backup's up their devices using iTunes or iCloud, only certain parts of the app's sandbox is backed up. So there are two important aspects here:
Only backup data that can't be replaced.
Be sure to backup irreplaceable data.
NSUserDefaults is one of the things that will be backed up for you. You don't need to do anything special.
You don't need iCloud support unless your app has a specific need to use it.

Scenario for offline file access

Scenario:
After downloading the file from Server, we have to store it in device’s local and fetch from their for later use.
This is for reducing unnecessary hits to DB to get the same file again and again. And accessing file offline too (when user don’t have internet access, he can able to fetch file from local).
How can we implement the above scenario in iOS devices for videos?
This solution will work only if files have unique names.
You can create a local db in which you have to store all file names which you have already downloaded from server.
Whenever user want to see a file you have to first check thes local db.
If file is already downloaded you can take the file and play it.

iCloud sync files and core data

In my app I save images in file manager and their metadata(image name,created date,notes and image path) in core data.
I want to know the best practice to sync these data using iCloud.
If you save the images in the ubiquity container they will be synchronised across devices. However you may need to store a relative pathname rather than an absolute pathname.
If you take a look at the the sample apps at the link below you will find the app uses iCloud to synchronise the Core Data database using transaction logs and it uses iCloud to synchronise the backup files the user makes. So while this is not exactly what you want it would be pretty easy to modify the code for saving the backup files to iCloud to save your files to iCloud.
You do need to remember that iOS will not automatically download files from iCloud so you would have to do that from your App prior to trying to use them on the device.
http://ossh.com.au/design-and-technology/software-development/

Can my app let users save some files to iCloud and rest on device

In Apple's Document Based App Development Guide, it emphasizes that our app should let users choose either to save all their files to iCloud or save all on local device. Is there reason for this? Can we actually allow users to pick some files to be saved on iCloud and some to be saved locally, like the TextEdit app on mac OS X? Will App Store disapprove iOS apps configured in this way if it is programmatically possible?
Thanks!
Here is a link
https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/ManageDocumentLifeCycle/ManageDocumentLifeCycle.html#//apple_ref/doc/uid/TP40011149-CH4-SW1
Setting the Preferred Storage Location for Document Files
All documents of an application are stored either in the local sandbox or in an iCloud container directory. A user should not be able to select individual documents for storage in iCloud.
When an application launches for the first time on a device, it should do the following:
If iCloud is not configured, ask users if they want to configure it (and, preferably, transfer them to Launch Settings if they want to configure iCloud).
If iCloud is configured but not enabled for the application, ask users if they want to enable iCloud—in other words, ask if they want all of their documents saved to iCloud. Store the response as a user preference.
Based on this preference, an application writes document files either to the local application sandbox or the iCloud container directory. (For details, see “Moving Documents to and from iCloud Storage.”) An application should expose a switch in the Settings application that enables users to move documents between local storage and iCloud storage.
If it makes sense for your app, there is no reason Apple would care if you save some files locally and some in iCloud. It's not a hard fast rule to be all one way or the other.

Resources