4
\$\begingroup\$

I want to award coins for doing thing in my app and let users purchase things with the coins that are non-consumables. I also want to let users purchase coins as IAPs.

How do I keep track of what has already been purchased between app reinstalls / new device installs? I know that it's not required to share consumable purchases (coins) between devices.

Do I need to setup my own server to keep track?

Is it possible to do within the Apple ecosystem without the need for my own server?

Can I just use local storage and not worry about it?

\$\endgroup\$

3 Answers 3

2
+100
\$\begingroup\$

I am not completely sure what you want to share across devices, the earned and bought coins or the purchased things (lets call them "hats").

I also do not have any experience with IAPs, iCloud and CloudKit, what I say here is only from observations and reading documentation.

IAPs can be restored, you can see that in almost any app that uses them to unlock features. If your bought coins cannot be consumed, that will help you get them back. If they can be consumed it will be a little trickier, especially since you will need to watch out for people modifying your data storage to cheat. In any case, unconsumed bought coins could be transferred like earned coins and hats (next paragraph).

Earned coins and hats need to be stored off-device somehow. You have several options here:

  • iCloud: For a simple counter (coins) and a checklist of fixed / small size, you could simply store them in preference files (google "iCloud key value storage"). These will then be synced. From what I hear, KV-storage via iCloud works reasonably well.
  • CloudKit: Storing data in iCloud using basically your own defined logic. More work than the above, but also more flexible. The storage limit should not matter for the problem you describe.
  • Your own server: The most work, and the most flexible. Also frees you from the Apple ecosystem, allowing e.g. an Android version in the future, with cross-platform data transfer.

It all depends on your needs, really. Choose the topmost option that suits all of your needs. In any case, cross-device data transfer can not simply be done with local storage. Restoring a new device from a backup would transfer data, but deleting the app and reinstalling it would purge the data. And using both an iPhone and iPad is also only possible with some sort of cloud-based synching mechanism (leaving out user-initiated WiFi-transfers, I don't think you want that).

\$\endgroup\$
2
  • \$\begingroup\$ So if you save something to iCloud what is the user context? Is it an iCloud store per device or per apple account or something else? \$\endgroup\$
    – Jason
    Dec 1, 2014 at 0:37
  • \$\begingroup\$ Yes, it is per Apple/iCloud account. If a user signs in to iCloud, every piece of data associated with that account is available to them/their apps as long as they have access to them (meaning you can't access another apps data, save for iCloud as a storage provider, which is a whole other topic and not relevant to your use case). The store is basically local, but synced across devices in the background, so expect some latency (a few seconds or so on a usable internet connection). \$\endgroup\$
    – Kolja
    Dec 1, 2014 at 0:53
1
\$\begingroup\$

There's no need to have your own server. Apple provides the ability to restore purchases; details can be found here.

You can simply add a button which calls

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

once you have an observer in your code, which looks like this:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

and purchases will be restored.

More on the SKPaymentQueue class can be found here

\$\endgroup\$
3
  • 1
    \$\begingroup\$ As far as I know purchasing something with "coins" in an app would not result in an Apple "transaction" that could be restored like a normal IAP. I am asking how to store and retrieve "faux IAPs" made with virtual currency. \$\endgroup\$
    – Jason
    Dec 1, 2014 at 0:34
  • \$\begingroup\$ I'm sorry; I'm not understanding. When you said the users could purchase coins as IAPs, I thought you meant they would pay real money for them. As for buying items with coins, you would simply save the required variables (userCoins, upgrade1, upgrade2, etc.) in iCloud backup. Let's say the user has a weapon they can upgrade 5 levels. Why could you not just keep track of the level it has been upgraded to and the number of coins they have? \$\endgroup\$
    – Matt
    Dec 1, 2014 at 1:21
  • \$\begingroup\$ Right, users CAN purchase coins with real money or earn them by using the app. I was under the impression that consumable type IAPs (coins) are not restored with 'restoreCompletedTransactions'. So I guess storing the things they have purchased with the coins and the amound of coins they have in iCloud is probably the way to go. \$\endgroup\$
    – Jason
    Dec 1, 2014 at 21:47
1
\$\begingroup\$

Personally I use a shared keychain entry enabling Keychain Sharing in the Capabilities of your target. This makes life so much easier especially given that this file is backed up and thus if the user changes the device they will not lose anything.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .