Are values stored in NSUserDefaults removed when the app that put them there is uninstalled? - iphone

If I put a token (a string) into NSUserDefaults, lets say as a paramter passed to a REST API that is used by the app, and the app is uninstalled, will the string remain on the device?

No, it will not. I use NSUserDefaults in the exact same manner, and it will not stay after the app is deleted. You can verify this via Organizer if you need to.
It will however persist through updates. I have been using TestFlightApp for all of my beta testing, and the token (and other saved user default data) remains. Hope this helps.

No. You can see that the data saved is in Library/Preferences/ inside your sandbox. If you are using Simulator, see (something like) ~/Library/Application\ Support/iPhone\ Simulator/4.3.2/Applications/00DB5581-E797-4AB0-9033-321ACD8938BD/Library/Preferences/com.me.MyApp.plist

Related

How can i come to know app is not installed first time on a device iPhone

I want to store some value when app is installed first time.
So when user delete and re install that app . read that value and take actions accordingly.
Is there any way ?
Scenario:
App installed first time store value somewhere.
User deletes app from iPhone.
Re install app again.
Read that stored value. ?
Is this possible ?
To achieve what you want, You can directly refer Keychain Data from Apple Documentation.
use the Keychain to store your data, because the Keychain items are not deleted even if the app is Uninstalled or removed.
This Api will help a lot Link, have a look

Cache on iOS, How to delete on relauch

I decided to import this project on my app i found on github lockscreen. Essentially it works just like the iOS pincode lockscreen but in this case it protects the app from being used a random snoopy person. The lockscreen works my issue is if in case I had set a passcode lock pin and delete the app off my iPhone and reinstall it the lockscreen still askes for to enter a pincode. I believe this is being caused form a cache storing the set pin codes for the app. Is the a way to delete the cache at relaunch or in the event of deleting the app ? I suppose this would be implemented in the delegate? How could you do this
Well yes and no. The passkey is stored in the keychain, from which you will need to remove it.
The way to do that is to check on startup that it is a new install of the app and clear the current value of the passkey form the keychain.
Since there is not code executed on the removal of you app you can't really do it after or when the app is removed.

Why can't our app store a simple key/value pair in iCloud?

I've configured our app for iCloud usage with the appropriate entitlements, under a provisioning profile that is set up for iCloud, and a developer profile that's associated with this provisioning profile.
The application identifier matches what's specified in the provisioning profile (com.ourcompany.ourproduct). I don't get any errors when building the app.
iCloud is enabled on my phone, and is working (as evidenced by my calendar, contacts, and bookmarks being updated).
And yet this fails (localID is a valid NSString):
NSUbiquitousKeyValueStore* iCloudStore = [NSUbiquitousKeyValueStore
defaultStore];
[iCloudStore setString:localID forKey:#"ourKey"];
If I call synchronize after this, it returns NO. If I allow plenty of
time for the update to occur, subsequent attempts to retrieve the data
still fail.
Any idea what the culprit could be here?
Thanks!
In the simulator, NSUbiquitousKeyValueStore will just store values on disk and won't even try to synchronize anything.
On the device, synchronize will generally fail because your kvstore-identifier entitlement is incorrectly set but you should then see an error log in your Console.
Are you running it in the simulator? iCloud sync doesn't appear to work in the simulator, only on a device. Beyond that, your code looks good. I would expect it to work.
I also noticed that I was able to store and retrieve keys even before I set up my entitlements. I'm assuming the entitlements just allow you to link a key-value store to your App ID so that multiple devices or multiple apps from your company can share a store.
Knowing this, you could try completely removing references to iCloud in your entitlements and see if that works. Just for testing purposes.

Iphone persistant preferences after app delete

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).

iphone keychain items persist after application uninstall?

I am playing with idandersen's scifihifi-iphone code for keychain and came across the following behavior - I set the password using, say
[SFHFKeychainUtils storeUsername:#"User" andPassword:#"123"
forServiceName:#"TestService" updateExisting:YES error:&error];
Then delete test application from device and install it again - the previously set password appears to remain in keychain...
Is it the expected behavior? And is there a way to make sure that password I set will be deleted with the application?
Yes, this is the expected and correct behavior.
Some keychain items may be shared with other apps you control (that share the same keychain item access group).
You should just leave the info alone when your app is removed. You have no callback or method of removing the keychain items on deletion of your app.
Edit:
They finally reverted the behavior described in my answers, so until everybody move away from that range of versions, this should not happen anymore.
Unfortunately, this is not the case anymore. It has been changed since iOS 10.3.
This is an intentional change in iOS 10.3 to protect user privacy. Information that can identify a user should not be left on the device after the app that created it has been removed.
It has never been a part of the API contract that keychain items
created by an app would survive when the app is removed. This has
always been an implementation detail.
See the reference here.