I want to store a date string in the iphone device, but not in the application context, because if a user deletes the app then that value is deleted too.
Is this possible?
Store it in the keychain. Keychain data is not deleted when the app is.
A possible solution is to store all the information on a server. You could use rails, php, or any other server framework to do this. Also, there's a new service that's trying to make it so you don't have to do any server coding at all: http://www.parse.com
If the application gets deleted on iPhone, all its related files are also deleted. Including files, SQLite databases and preferences.
If you want preference to persist after deletion, you will need a server and allow the user to store that information there (in the cloud).
Related
We are storing a unique identifier for the mobile device in an SQLite database, to be used for licencing purposes. The problem is that if a user removes the application then reinstalls it again, the SQLite database is gone along with our stored variable.
How to prevent removing the databse upon application installation, so that we can reuse the database if the application was reinstalled again
Thanks
You can approach this by sending the information to a server side, you can't store any data out side the application sandbox.
You could:
Store the key on your own server
Store the key in the device's keychain. Notice that you won't be able to remove the key from the user's keychain after the app has been removed from their device. More info about the keychain here: https://developer.apple.com/library/ios/#documentation/Security/Reference/keychainservices/Reference/reference.html
In the program you can create a copy of the SQLite database. Simply drag and release the database into the program resources.
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.
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.
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.
What code could I use in an iPhone app to get and set the settings of another app I wrote? (preferably using NSUserDefaults)
You're not going to be able to pull this off with NSUserDefaults.
The Keychain, while somewhat cumbersome in its C-ness and much more limited than the NSUserDefaults API, might allow you to accomplish this. If you can serialize whatever you need to share between your apps into a few strings, it might be worth trying.
From iPhone OS 3.x Release Notes:
It is now possible for you to share Keychain items among multiple applications you create. Sharing items makes it easier for applications in the same suite to interoperate more smoothly. For example, you could use this feature to share user passwords or other elements that might otherwise require you to prompt the user from each application separately.
Sharing Keychain items involves setting up the proper entitlements in your application binaries. Using Xcode, you must create an Entitlements property list file that includes the supported entitlements for your application. The process for creating this file is described in iPhone Development Guide. For information about the entitlements you can configure, see the description for the SecItemAdd function in Keychain Services Reference.
Accessing shared items at runtime involves using the Keychain Services programming interface with the access groups you set up during development. For information about how to access the Keychain, see Keychain Services Programming Guide.
Here's Buzz Anderson's Simple iPhone Keychain Code. You could use it to store key/value pairs as strings in the keychain. It's not much, but perhaps better than nothing. See Apple's Keychain Programming Guide for more.
You simply cannot do that. Each application is installed into its own folder and is given its own, unique user id. The file containing these settings is in the other application's folder and its permissions are set to that of the other application. The only way to access the data is to use the same application identifier as the other application, in which case installing your application would overwrite the old application.
EDIT:
This solution was given when the question was asking to do this using NSUserDefaults, specifically. For the updated question, the keychain approach or the server approach provided are both reasonable.
You can have one app send the data to your server, then the other app can get the data from your server.
You can't do this using NSUserDefaults but it can be done.
You could use a shared clipboard. It wouldn't be secure, but both apps could read and write from the same clipboard. You just need to create an application specific UIPasteboard. Check out the UIPasteboard class reference on Apple's developer site for more info.
--Mike
You should definitely have a look at UIPasteboard, as suggested – you can create a new pasteboard for use by the applications you are creating (though nothing will stop other apps using them, but people are faily unlikely to). A UIPasteboard is persistent through a power cycle / reboot – it will exist until the creating application is deleted.
You could also have a look at the SwapKit libary (which looks very cool):
http://infinite-labs.net/swapkit/