As you know that when we share data between two apps in iOS, we can use keychain. And iOS8 later, we can also use app groups to implement the same function;
My question is what's the difference between keychain and app groups, which one will be better and why ?
Keychain
If we save the data in the keychain, it still remains there when you uninstall the app unless it is completely reset.
For example, you might implement some login functionality and save it in the keychain. If the user uninstalls the app later then re-installs the app, you can grab those values from the keychain.
App groups
App groups are mainly used when you want to share data (for example SQLite or Core Data) between your apps.
For example, if your app has a widget and it wants to get data from SQLite or Core Data, then you would create an app group and save the SQLite or Core Data file in that app group path instead of the app's document directory. Now both your widget and app can track the changes in your DB file.
These are some common examples of the things you asked.
Related
I have an application that is implementing storage using Key/Value pairs in iCloud. From what I read in the documentation this is almost identical to the way NSUserDefaults work.
However this potentially creates a problem because the user should not have the ability to tamper with the app data stored in there. Does this mean that the user can access this data and modify it? Or is it private to the application?
Okay reading deeply in the documentation it says
If your app needs to store passwords, do not use iCloud storage APIs
for that. The correct API for storing and managing passwords is
Keychain Services, as described in Keychain Services Reference.
I found this text here just one line before the last table :)
I also found somewhere that the user can delete his iCloud data manually which can be counted as a modification.
Also, read here, section fro "Start Fresh If Your iCloud Data Becomes Inconsistent During Development" where it says how you can clean the container. Maybe you can check what is visible inside.
It depends what type of data you are storing in the iCloud if it's sensitive then I would use keychain services approach and avoid storing sensitive information on the iCloud.
From the question it seems like you are storing the data in key-value pairs, usually, it's recommended to store preferences, settings, and simple app state and that should be ok because the user can change those, you should choose the right iCloud API for what you want to store
With iCloud the user can always delete the information it has stored as mentioned in the documentation
There may be times when a user wants to delete content from iCloud.
Provide UI to help your users understand that deleting a document from
iCloud removes it from the user’s iCloud account and from all of their
iCloud-enabled devices. Provide users with the opportunity to confirm
or cancel deletion
When you ask
Or is it private to the application?
There's an iCloud identifier in your entitlements file. If it's the same in both apps you'll be able to access the same data/documents across both the apps.
Hope that helps.
So I developed an iOS app called Due it a while back, and I had no idea what I was doing at the time. Anyhow, I lost all of the files for it, so i decided to re-create the project, but I stored data in Keychain on the old version. Is there any way that I can get the Keychain data back? (im using the same Bundle Identifier)
I've tried using this: https://stackoverflow.com/a/44310869/4705065 but it doesnt find any data.
Not at this point.
You are able to add multiple applications to a Keychain Access Group within an app, but you would have had to do that within the original app you no longer have access to.
More information on Keychain Access Groups.
It would be a big security concern if anyone could access anything within keychain without explicit permission.
My app is a Gov app where a user captures photo and record some notes about it.
When the user removed the app, all data are lost.
Is there a place where I can store data (notes & photos) for the user even if they removed my app, then installed it again, it will be still there?
Note: This can be done easily with Android, by using a public directory.
Use server to save large files.
and keep user token in keychain. The data in keychain will NOT be deleted when app was deleted.
when user reinstall your app, you can get this token, and use it to download large files.
iCloud is other space to save your data.
I want to save no sensitive data in my app,
The data not delete when the app delete.
I saved in keychain but I see that In keychain save only sensitive data.
where I can to save my data?
There is no such place on iOS where you can save data that stays on the device even if your app is deleted, except for the keychain...
This is because your app is running in a Sandbox that holds all the data that belongs to your app. You have a few possibilities to achieve persistence within the context of your app (e.g. using the Documents directory of your app, NSUserDefaults or Core Data,...), but for any of these, there is the restriction that the data gets deleted along with the app.
The other option is to store the data in the cloud, either writing your own server side system to store the information or using a service like Parse.com
I'm making an app for iOS devices. It's not my first app but it doesn't important. My app use NSUserDefaults to store data which are using during application runtime. All works good while user wants to delete app. After this and after installing/compiling app again on same device all settings from NSUserDefaults are removed - It's look like app is first time on this device.
The question are:
How should I store data if I want to read it after removing and installing again an app?
If not NSUserDefaults then where to store this data?
Thank you in advance.
the nsuserdefaults are not preserved. nothing in your app's sandbox is BUT for the keychain. values in the keychain are not erased.
so use the keychain for values that you want to keep.
BUT don't store everything in there. normally when a user deletes an app he wants stuff gone.
the only other way I can see would be your own server where users can store backups, the dropbbox api or icloud
I think you could store defaults in your custom plist, and then use iCloud, which is built in iOS. iCloud will automatically backup documents from your app, and then you have them available on new installations since apple handles this.
Have a look at apple's official documentation about storing key value data on iCloud:
https://developer.apple.com/library/ios/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForKey-ValueDataIniCloud.html#//apple_ref/doc/uid/TP40012094-CH7-SW1
In that link they explain how to add key value data on iCloud to your app.
You want to use the keychain, docs here.
This is the only way on the device. Possibly you could use iCloud depending on exactly what you're trying to achieve.