saving a file outside of my application bundel in iphone - iphone

i want to save a file outside of my application bundle as a backup of database so that when user reinstall my app or my app crashes he can backup his data from that location.

Apple already does this, with iTunes.
What you are asking is technically against apple's policy, unless you store it off site, on a server (which you could easily do)
If you have a lot of applications, I'm not aware of the policy, but perhaps you could make an app to back up your other app's data.

Related

How Can I Setup My iOS App To Use Automatic iCloud Backup?

I have written an app the uses the RealmDB, which produces a file called default.realm. This is the database storage file. I would like to setup my app to make use of the iCloud automatic backup feature. How can I setup my app to do this?
You can't! Because your app is already set up like that! :)
According to the File System Basics page on Apple's website, all files in an app's Documents folder will automatically be backed up to iCloud, or the user's local iTunes account if they've chosen such. This is on by default, and must be explicitly disabled through code if disabling backup is desired.
By default, Realm places default.realm in the Documents directory for this exact reason: to ensure any user-generated data stored in it will be properly backed up in through iCloud and/or iTunes sync operations.
So you don't need to worry! Your Realm data is already being properly backed up by iCloud as we speak! :)

How to update iOS app with exception of a file

I'm making my first iOS app. And I have a question.In my app I want to save the current state of the app: levels completed, score reached, money, in-App purchases, etc. in a Settings.plist. The problem is, how can I place this plist so that if the user updates the app, he/she not to lose these settings. I read about The app sandbox, but I don't understand
how it works, and how can I manage that from Xcode.
You should store these settings in the NSUserDefaults. They are kept when new app versions are installed, so you won't have any problems.
Two points:
a) When you update your app after its in the app store by submitting a new version of the same app the files created by the old version will not be lost. So you can store whatever you like in the app's Document or Library directories and expect it to still be there after an update. The Library/Caches directory will not be backed up or restored by iTunes so don't put anything there that you can't re-create. If you submit a different version of the app (not an update but a new app, so you have two separate apps in the app store, perhaps free and paid) there is no way that I know of for the new version to get to the files that the first version created.
b) It's easy for the user to read, delete, or change whatever files you create in Documents/ or Library/. It can be done with an app on his/her Mac such as iExplorer (downloadable from macroplant.com). So be aware that if the file is human-readable, which a .plist file is, the user can change it to improve his/her score, get more consumables, or whatever. You can prevent that by encrypting the data, or somehow obscuring the meaning, or by some kind of checksum scheme so you can at least detect that it was changed. Any of those measures involve complications of course and may not be worth the trouble.
BTW... if you're developing an app that uses data files iExplorer is a great debugging tool. I have no vested interest in it except that I've learned how to use it and want it to continue to be supported. There are probably other apps that do the same thing but this one works great and is fast and easy to use.

Will iCloud keep user's data that was belonging to a deleted app?

My use case is:
User downloads my app and uploads some data/Files onto iCloud within the sandbox of my app.
User deletes my app
Questions:
Will iClould keep user's data that was belonging to the deleted app? (Based on my experiment, the data is kept on iCloud when my App is deleted, however, I am not sure whether the behaviour is official).
If the answer is Yes, then I have the following questions:
a. How user's data eventually get deleted/cleared from user's iCloud storage? (My concern is that if the user decide never to use my app again, the data would become useless therefore should be cleared on iCloud to free spaces)
b. If user decide re-download my app, how can he get access to the data iCloud he originally uploaded?
c. Can I manage the user's data from iCloud web portal (www.icloud.com)? I don't see my uploaded document appears in iCloud web portal, even I put my files under "Documents" subfolder.
d. Is there any official documentation that describes this behavior?
Thanks in advance!
Yes, iCloud will keep a person's data belonging to the deleted app by default.
Follow up questions
A: The data will stay in iCloud storage until the person decides to delete the data. Using the Settings app, a person can manage their iCloud storage, down to turning off backups of each app's storage. Or the entire backup for a device can be deleted to start over with a fresh backup.
B: If a person reloads an app on their iOS device, meaning any app with the exact same App ID so it could be an updated version, iCloud should restore the data from the app's backup.
C: No, the iCloud Web portal only gives access to the apps loaded by Apple, currently Mail, Contacts, Calendar, Find My iPhone, and iWork. Apple could offer the ability to add apps to the iCloud Web portal, just like we add apps to our iOS and Mac devices. But that would be some future offering.
D: Much of this is documented in the developer documentation. Some of this answer is undocumented, and gleaned from experimenting with iCloud (so please correct me where I'm wrong).

How to make a backup of my app (iPad)?

i am new in programming and have some troubles with backup.
I have an App with SQLite database and different user params in it. All data will be saved, after I leave application. But if I reinstall it, all data is lost.
So, i think i need some kind of backup for this data. I mean is there any way, how to save SQLite db outside of apps folder?
Updating the application will not overwrite your data, but deleting the app will remove all data. You don't need to delete the application each time you redeploy to your device or simulator.
Your application doesn't have access to anything outside of it's sandbox, so saving outside the apps folder is out of the question.

Removing keychain data on uninstall

Does anyone know of a non-programatic method of removing data stored in the keychain when the application is deleted from the device?
I've read on several threads on SO that the data will persist even if the application is uninstalled and my experience confirms this is true.
However this seems contrary to what is specified in Apple's iOS Application Programing Guide: "The keychain data for an application is stored outside of the application sandbox. If an application is uninstalled, that data is automatically removed".
You could wipe the iPhone by using Erase all Contents and Settings.