Is there a suggested way for delivering In App Purchase contents to the client?
I am developing an iPad game that lets you buy new game 开发者_如何学JAVAlevels (that basically are a set of pictures associated with some title and description) with the StoreKit. Those sets of pictures are stored in the cloud. The StoreKit programming guide doesn't really give tips on how to fetch content from the server, and I'm stuck in figuring out what would be a good design practice here. There are a couple of implementations that come to my mind:
- Fetching the whole content as a compressed archive and uncompressing the archive on the client, following a known convention about directories and files, and checking for the existence of a directory to know what additional levels the user bought.
- Fetching the content one picture at a time and then serialize and store the set with
NSKeyedArchiver
in a file that has the same name of the Product ID. To check if the user bought a particular set I would then check the existence of a file named like the Product ID. - Same as 2, but using the Core Data framework instead.
I think that the Core Data solution has the advantage that the images data won't be loaded until it is really requested (since the memory constraints on the iPad are pretty low). Memory optimization might be important since I need to display thumbnails of those pictures without the need to load in memory the whole full-sized set. The compressed-archive solution also has this advantage.
What practice would you suggest?
You are conflating two separate questions here: how the fetch the content and how to store it on the device.
To fetch the content, the best bet probably is to fetch an archive of some sort and unarchive it on the device. This archive could be a zip file, an XML file with the images base64-encoded as values of some nodes, or a custom binary file format, that doesn't really matter. I would avoid downloading each individual resource separately, as that can easily leave you with a situation where the data is only partially downloaded.
Once you have the archive, you'll need to uncompress it and store the contents on the device. Whether you store it as files in a directory structure, as a serialized NSDictionary in a file, or as objects saved in Core Data is up to you. Both the directory structure and the Core Data solutions have the advantage that you can easily load only the individual resources as needed. Either one is a valid choice, use whichever works best for your situation or whichever you're more comfortable with.
精彩评论