I currently have an iOS application for which I would like to enable iCloud score storage so that users will have their game progress synced across their devices. The users progress is stored in multiple plist files in the sandboxes documents folder.
I read a few articles online about iCloud and the various "helper classes" (NSFileManager, UIDocument, NSFileCoordinator etc.) but am a little confused which one is the right one for me (does NSFileManager do the job or will i need to subclass UIDocument).
The API's are all a bit confusing to me.
You should use iCloud with Key-Value Data Storage. It's by far the simplest and most reliable at the moment, and suits your case perfectly.
Related
I wonder as one of my personal projects development goes further forward how should i organize the files ( images, videos, audio files ) uploaded by the users onto AWS's S3/GCE Cloud Storage, i'm used to see these kinds of URL below;
Facebook fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xft1/v/t1.0-9/11873531_1015...750483_5263546700711467249_n.jpg?oh=b3f06f7e...b7ebf7&oe=56392950&__gda__=1446569890_628...c7765669456
Tumblr 36.media.tumblr.com/686b47...e93fa09c2478/tumblr_nt7lnyP3ld1rqbl96o1_500.png
Twitter pbs.twimg.com/media/CMimixsV...AcZeM.jpg
Does these random characters carry some kind of meaning? or they're just "UUIDs"? Is there a performance/organization issue in using, for instance this kind of URL below?
content.socialnetworkX.com/userY/post/customName_dinosaurs.jpg
EDIT: Let be clear that i'm considering millions of files.
For S3, see the Performance Considerations page where it talks about object naming. Specifically, if you plan to upload objects at a high rate, you should avoid sequentially named objects, as they can be a bottleneck.
Google Cloud Storage does not have this performance bottleneck. See this answer.
I store some preferences in iCloud with a help of [NSUbiquitousKeyValueStore defaultStore]. Can foreign apps get data from my app cloud using my app cloudURL [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil] or using something else? If yes, how can I protect my data?
As far as I know, every app works in its own sandbox and therefore it is not possible to get data from other (3rd party) apps - it doesn't matter whether they store their stuff in iCloud or on the device.
If you want to provide some data from one of your apps for other apps then you need to provide them on your own server so other apps can download what they need.
But of course the people owning the actual device can access all information stored on the device if they use programs on their computers that allow people to access iPhone's file system.
Hi I am looking for some tutorials on using NSFileManager to store data in the directories such as cache and such, I havent really been able to find a good one with any nice examples. Any recommendations on where to find some? Thanks. ps. I know there is core Data too but at the moment I am just interested in finding one for NSFileManager
I have an app that displays some photos and I want to cache the seen photos so that I dont have to redownload the photos that have already been viewed
see NSURLCache
Class Overview:
NSURLCache implements the caching of responses to URL load
requests by mapping NSURLRequest objects to NSCachedURLResponse
objects. It is a composite of an in-memory and an on-disk cache.
Methods are provided to manipulate the sizes of each of these
caches as well as to control the path on disk to use for persistent
storage of cache data.
I am looking for a simple way to detect if a document has been uploaded or modified in iCloud.
The solution I have found for the moment is to poll at given interval the /private/var/Mobile Doc... folder relative to the application and containing iCloud docs, and see if a new document has a recent modified date.
It basically works, but I would like to know if there is some kind of NSNotification, as it is for example in CoreData+iCloud, or if there are other ways I don't know.
Thanks.
A NSMetaDataQuery might be what you are looking for. Have a look at the Standford iOS videos (available at iTunes U). The NSMetaDataQuery is used in the Core Data and iCloud-Sessions to monitor the content of an iCloud directory for changes.
Within a Mac OS X (10.7 Lion) Non-Document Based application, I want to include iCloud support so I can share data across other instances of the same application on other macs (not to iOS devices). After surfing around the Apple documentation a bit, I've discovered I should use a key value list storage in iCloud, as the document I want to upload contains only an array of custom objects (that have simple properties such as a name (string), date (date object), ...). This file is the only thing I want to upload to iCloud. Within the application, I have already implemented saving the file to the disk using NSFileManager's - (void)writeData:(NSData*)data toPath:(NSString *)path (or whatever it was, I've forgotten). It is loaded from the file using NSFileManager again (using - (NSData *)dataInFileAtPath:(NSString*)path, or whatever it was). The file is stored in a subdirectory, in the user's Application Support directory. It is saved whenever a new item is added to the array, or an item in the array is modified.
I was wondering if anyone could provide a link to a tutorial, or point me in the right direction, to writing that file to iCloud, then downloading it again on other instances of the same application? All the tutorials and documentation I have found have only been for iOS. Any help will be greatly appreciated!
Thanks in Advance!
Ben
Just use NSUbiquitousKeyValueStore, which is a lot like NSUserDefaults except that it's written to iCloud. You should read the iCloud Storage section of the Mac App Programming guide, but what you need to do may be as simple as enabling entitlements in the Summary tab of your App Target in Xcode, and then doing something like:
NSData *dataToStore = [NSKeyedArchiver dataWithRootObject:yourArray];
[[NSUbiquitousKeyValueStore defaultStore] setData:dataToStore forKey:#"yourKey"];
Then, to retrieve your data, just do
NSData *retrievedData = [[NSUbiquitousKeyValueStore defaultStore] dataForKey:#"yourKey"];
NSArray *retrievedArray = [NSKeyedUnarchiver unarchiveObjectWithData:retrievedData];
The one caveat here is that for this to work with an array of custom objects, these objects must all implement the NSCoding protocol. This is just a matter of implementing two methods; here's a good tutorial.
P.S. You use the same APIs whether you're developing for OS X or iOS, so there's no reason why you couldn't just follow an iOS tutorial for iCloud storage.