oleynikd
oleynikd

Reputation: 932

Persisting a Receipt in iCloud using CloudKit in iOS

#1

I'm developing iOS App with a non-renewing subscription in it. I want to make the subscription available on all of the user’s devices and to let users restore the purchase.

As said in Apple's docs:

For non-renewing subscriptions, use iCloud or your own server to keep a persistent record.

I do not what to use my own server because my App is available only for iOS for now. So iCloud seems to be easer solution.

After watching and reading A LOT of WWDC videos and docs about iCloud seems like the best solution for me is CloudKit because Key-value storage is limited to 1MB and I have a big chances to get total data size bigger than this per one user (after a year of different purchases for ex.).

Question is: am I right so far?

#2

I'm using RMStore Library for purchases. As is it said in docs RMStore doesn't have reference implementation of Transaction persistence to iCloud and I couldn't find any examples in the Internet so I'll have to do it by my own from scratch.

The first problem staring me in the face is: what if there will be some problem syncing the receipt to iCloud after user has purchased the subscription? For example: user bought the subscription, got some error syncing it to iCloud, closed the App and that's it. Is this a real scenario? For non-renewing subscriptions receipt is not stored anywhere by Apple so I am fully responsible for delivering and saving it for my user. Should I immediately save the receipt in NSUserDefaults or in Keychain after transaction is finished to be able to compare synced data to local one next time user launches the App? Or maybe I should not 'Finish the transaction' until receipt is synced? I could not find any guides from Apple for this...

#3

The next obvious question is: Can user clear my App's iCloud private storage? Can user somehow delete stored in the iCloud receipt thereby deleting all information about his purchases? If yes - how should I handle it? If this scenario is real I have no way to recover his purchase and open App's functionality for him until he buys subscription again.

Thank you in advance.

Upvotes: 3

Views: 957

Answers (1)

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

  1. CloudKit is not limited to 1MB. A record is limited. But if you have more than 1MB of data in a record, you should consider a refactor. If it's just some sort of data blob, then you should save it in a CKAsset. For that the limitations is much higher.

  2. Syncing will be a problem no matter what technique you use. One way to improve on that is by registering a begin purchase flag, then do the purchase and after that set the purchased flag. Then if a record stays in the 'begin purchase' state you know something went wrong and you can check with the App Store if the purchase was successful.

  3. you should add a restore purchases function to your app

Upvotes: 2

Related Questions