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/
Related
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.
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 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)
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.
In Apple's Document Based App Development Guide, it emphasizes that our app should let users choose either to save all their files to iCloud or save all on local device. Is there reason for this? Can we actually allow users to pick some files to be saved on iCloud and some to be saved locally, like the TextEdit app on mac OS X? Will App Store disapprove iOS apps configured in this way if it is programmatically possible?
Thanks!
Here is a link
https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/ManageDocumentLifeCycle/ManageDocumentLifeCycle.html#//apple_ref/doc/uid/TP40011149-CH4-SW1
Setting the Preferred Storage Location for Document Files
All documents of an application are stored either in the local sandbox or in an iCloud container directory. A user should not be able to select individual documents for storage in iCloud.
When an application launches for the first time on a device, it should do the following:
If iCloud is not configured, ask users if they want to configure it (and, preferably, transfer them to Launch Settings if they want to configure iCloud).
If iCloud is configured but not enabled for the application, ask users if they want to enable iCloud—in other words, ask if they want all of their documents saved to iCloud. Store the response as a user preference.
Based on this preference, an application writes document files either to the local application sandbox or the iCloud container directory. (For details, see “Moving Documents to and from iCloud Storage.”) An application should expose a switch in the Settings application that enables users to move documents between local storage and iCloud storage.
If it makes sense for your app, there is no reason Apple would care if you save some files locally and some in iCloud. It's not a hard fast rule to be all one way or the other.