iCloud setting like clear app in ios - 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)

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.

Save user defaults to iCloud

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.

How do I enable iCloud and migrate Core Data on a release update?

I have a released V1.0 of an iPhone App which uses Core Data but no iCloud.
Now I will like to release V2.0 with iCloud support.
I am using https://github.com/mluisbrown/iCloudCoreDataStack/blob/master/iCloudCoreDataStack/PersistentStack.m as a template, and everything seems to work.
Because the previous release did not have iCloud, and the new one will, I will like to migrate the local copy to the iCloud one on the first time the user opens the new version.
How do I do that? Can I simply somehow copy the whole sqlite file from local to iCloud? The schema is the same between 1.0 and 2.0.
I plan to ask the user if they want to use local Vs. iCloud (as per guidelines), but if they say Yes, I want to just do a bulk copy somehow.
Thanks
I have just posted a sample iOS library style Core Data app which includes iCloud integration. The app includes a Settings Bundle for the user to toggle "Use iCloud" preference settings and will migrate the store to and from iCloud depending on the users settings.
Download from the link below - sorry about the documentation - will get around to that at some point but it works much the same way as the UIManagedDocument example.
http://ossh.com.au/design-and-technology/software-development/
You can't bulk copy, you have to use proper API [NSPersistentStoreCoordinator migratePersistentStore:...] and [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:...] with iCloud options to migrate the store to iCloud. I have attempted to document how to do this (but the example uses UIManagedDocument, although the Core Data APIs for migration to and from iCloud remain the same).
Not only do you have to check the user preferences you also have to check whether they are logged in to iCloud. Also you have to migrate to iCloud and then you have to be able to migrate back to Local if the user changes the preference. So you have to check whether the user has changed settings whenever the app becomes active. It is not that straight forward to do but it's not to hard once you figure out the logic required.
See the link below for a more detailed explanation, sample code, and a video showing the app working and the creation/removal of files in the local and iCloud containers:
http://ossh.com.au/design-and-technology/software-development/uimanageddocument-icloud-integration/
Remember you will have to remove the UIManagedDocument specific code from the example.

local core data store with icloud

I have a question regarding icloud store with core data store in iOS7. In the apple WWDC conference, it was mentioned that the core data store can be created in the sandbox and when the app starts receiving responses from icloud, the changes in the core data store will be merged into icloud store.
Now, (I might be wrong), but the conference further mentioned that the local core data store would be deleted once the app has switched over to the icloud store. So, my question is can a local core data store co-exist with the icloud store in iOS7 (so that the user has capability to work offline with data) ? And is there any sample code for this ?
In iOS 7, the Core Data framework takes care of managing the local store until the iCloud store is setup and available. This pattern also works for when the app is offline and it doesn't delete any data when the app goes offline (just double checked on my app in development).
The iCloud store will be deleted in another case. That's in the event the iCloud user account changes in which case the respective iCloud store file will be removed. In such case, there is a new API NSPersistentStoreCoordinatorStoresWillChangeNotification that allows you to store unsaved data before the store becomes unavailable. If the user logs in later with that same account, the data will be restored from iCloud (check the WWDC 2013 session 207 video at 15' for more on this).
As for sample code, there isn't any as of today. There is, though, iCloud sample code shared by AppleSpaceMan on the developer forum, which is what I used as a base and worked nicely.
You can work offline(no network connection) with the iCloud store as long as you have an iCloud account and are logged in to that account. I have just posted a sample application that includes the following features:
Use of Local or iCloud Core Data store
Includes a Settings Bundle (note that this creates a settings page in the Settings App) that includes:
Use iCloud preference setting (ON or OFF)
Make Backup preference setting (ON or OFF)
Display application Version and Build Number
Prompts the user about storage options when the Use iCloud preference is changed to ON
Migrates Core Data store to and from iCloud depending on the users preference setting and response to prompts
Detects deletion of iCloud store from another device and cleans up by creating a new empty iCloud store
Checks for existing iCloud files when migrating local store to iCloud and prompts user whether to merge or discard data in local store if an iCloud file exists
Makes a Backup of the Core Data store if Make Backup preference is set to ON.  Backup file name is persistentStore_Backup_yyyy_MM_dd_HH_mm_ss. To use it:
set Backup preference ON and next time the app is activated it will make a backup of the current Core Data store and reset the preference to OFF
file can be copied to PC or Mac from iTunes
to restore simply set app to use Local files (Use iCloud preference OFF) and replace the persistentStore file with the required backup file (note the file must be called persistentStore).
to then share restored file via iCloud again turn Use iCloud preference to ON and run App
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/

Resources