22.5. Storing User Documents in iCloud
Problem
You want to allow your users to create documents in your app, and you want to have those documents present on all devices that the user owns.
Solution
Use UIDocument
.
Discussion
Although a user can have many files of different types stored on her device by different apps, each app has to be considerate of the amount of data that it puts in the user’s iCloud storage. Therefore, only the data that the user generates while using your app should be saved to the user’s iCloud storage space. For instance, if you are creating a web-browser app, the data that your browser app caches on disk on the device should not be stored in the cloud. Why? Because that data was not generated by the user. Your app simply was trying to give a better user experience by caching the data so that the next time it accessed the same series of web pages, the pages would load faster. If you look at it from the user’s perspective, she didn’t really ask you to cache the data. What’s even worse is that your app is now using the user’s iCloud storage (for which she probably paid) to store cached data. That is simply wrong. You must tell the user what data your app is storing in the cloud, and if she doesn’t allow you to use her cloud storage space, you should avoid using that space and just store the data locally in your app’s sandbox.
One of the most confusing aspects of iCloud is how you, as the programmer, will need to manage the data stored in the cloud. Before iCloud, ...
Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.