Save user defaults to iCloud - ios

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.

Related

Storing a text file in iCloud in Xamarin

I need some clarification and Microsoft documentation is only confusing me more.
I want to save a txt file in iCloud so the user doesn't loose some data that belongs to them.
This db document is some information I am retrieving from a local database and storing in a text file. I have seen two ways of doing this.. however all the posts on this topic are very outdated and I don't know which way might be best or if they are even doing what I trying to do.
All I would like is to be able to have the user backup this particular file to their iCloud account, so they can still keep this info even if they change phones or delete the app and want to restore from iCloud.
Microsoft's documentation points me to this page https://learn.microsoft.com/en-us/xamarin/ios/data-cloud/introduction-to-icloud
I began setting up the provisioning profiles and setting the iCloud options on the entitlements page etc. However the documentation when sideways for me when they began creating a monkey page UI Document and having the user manager the ubiquity documents (which I don't want) I actually don't want the user even seeing this Txt file. However this option shows how to check if the iCloud is even turned on on this user's phone.
Now this other option I think is more straight forward and I read the documentation on it here https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system using something like this to store and retrieve a document:
var libraryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "..", "Library");
However what if iCloud is turned off? Is this an automatic backup option?
Any type of explanation is helpful.
The iCloud storage API in iOS 5 allows applications to save user documents and application-specific data to a central location and access those items from all the user's devices.
About the definition of iCloud, you will know that it will save your data to cloud server. And it can be used in all the user's device if turn on the iCloud.
However what if iCloud is turned off?Is this an automatic backup option?
Therefore, if iCloud is turned off, you could backup the data in device although it will not be used for other user's devices. You could save it in Application directories. This should be a good chooice to backup your data. And you also can get the data when you need them.
In addition, you also can use other cloud server APIs to backup your data. Such as Azure Storage, Firebase Storage etc.

Is data stored in iCloud using Key/Value accessible by users?

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.

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?

iCloud setting like clear app in ios

I have tried many iCloud example but I want to migrate iCloud to local and local to iCloud without duplication like in Clear app in ios. I have tried this example too
iCloudStoreManager
Can You please help me to solve it.
You can try the following:
If the user wants to keep the cloud data, delete the local store before creating the persistent store with iCloud settings turned on. iCloud should then populate your local store with the data from the cloud automatically.
If the user wants to keep the local data, migrate the existing local store to a new temporary store with no iCloud settings, then use the NSPersistentStoreCoordinator method
+removeUbiquitousContentAndPersistentStoreAtURL:error: to remove the existing iCloud data. Finally, migrate the temporary store back with iCloud settings turned on. You should end up with only the data from the temporary store.
Another option is to not remove any data at all, but deduplicate data as mentioned by Tom Harrington.
Lastly, you might have more luck with the Ensembles open source framework. It works with iCloud, but — being an open source project — is more transparent than Apple's solution, and generally easier to get up and running. (Disclosure: I am a developer of Ensembles)

How to store user-data correctly on iOS? Case with NSUserDefaults

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.

Resources