Reputation: 12820
I want to integrate in-app purchases into my application, and so I'd like to download .plist files whenever users buy new level sets. How can I download a file from a server and save it so that it stays in my iPhone app forever ?
EDIT
I want to achieve something like that:
isPurchased
or so, right ?
If the user purchased the category, the boolean is set to YES
.
Whenever new categories are added by me, I'll just have a whole new update like "Cut the rope" for instance do it. Is that a good approach ? Upvotes: 1
Views: 6214
Reputation: 1137
First: Why don't you use Apple's services for In-App purchases? Why using your very own implementation? I am not sure but...do you think you will get Apple's approval? As far as I remember, Amazon did something similar in the past and they didn't get it.
Second: I wouldn't use NSData for this purpose. If you have a valid property list, then it is the best solution to use
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"foobar.com/plistfile.plist"]];
You could then store this dictionary. To be honest, I wouldn't recommend using your solution. If I understood you correctly, you would have thousands of plists after some time. My suggestion: Use a "global" mutable dictionary as ivar of your App Delegate for example. This should be empty at the beginning. Then download your helper dictionaries as mentioned above and populate your global dictionary with
[[delegateInstance globalDictionary] addEntriesFromDictionary:dict];
each time you get new data.
Save it with
[[delegateInstance globalDictionary] writeToFile:@"path" atomically:YES];
and recover it each time your app starts up.
EDIT:
Of course you can do it that way. If these plists really store information, that's fine. For example you could store billing information there, so that they are not interchangeable for other users (or shouldn't be at least). BUT: If you only want to get information about the question if a users bought a specific level or not consider combining your information within one plist (as described above). Anyway: Consider a possibility for your users to get back their data. Think of somebody deleting your app accidentally. How do you want to explain to him all his purchases are lost? In-App purchases are safer.
Or at least: Store a copy of the receipts on your server and let the users login to gather what they paid for in the past ;-)
Have fun and good luck! :-)
Upvotes: 1
Reputation: 12842
Quick and dirty one-liner:
[[NSData dataWithContentsOfURL:@"http://<yourfile>.plist"] writeToFile:@"pathforthefile.plist" atomically:YES];
Upvotes: 0