9

In my app I have items to show just for users that are pays for subscription. User can log to app by e-mail and password and can logout and on same device can log different user.

My problem is that Apple Id in phone is still same. So when different user logged in he could restore purchase even that he didn't pay anything.

So my question is how can I fix it? How can I connect Apple account to my custom account? Or at least somehow when trying to restore IAP check that this Apple account already have this subscription but different user was logged in. How other apps do this? Thanks

Edit: I want to use Auto-renewing subscription in my app and I just don't know how to connect it to my custom account system.

Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
  • I think Apple would reject an app with this implementation. In App Purchases need to be tied to AppleIDs and you aren't supposed to have logins before users can access IAP content. I've just had a couple apps rejected (now accepted) because of the 17.2 guideline: https://developer.apple.com/app-store/review/guidelines/ – r3c0d3 Apr 07 '16 at 19:06
  • I've worked on the app where we did what I described below. However, we did not specially use email but rather "username". They could make that their email if they wanted. It was required to have a login before using the app. – Mobile Ben Apr 08 '16 at 06:25
  • @r3c0d3 I cant find 17.2 guideline. where is that ? – omarojo May 13 '20 at 00:29
  • @omarojo The guidelines have been re-organized. Check out 3.1.2(a) Permissible uses (of payments) – r3c0d3 Sep 03 '20 at 21:51

1 Answers1

17

When a user makes an IAP, you will not know the Apple Id used to make the purchase. What you will know, however, is the transaction id for the purchase. What you will want to do store the transaction id of the original purchase with your custom account.

When a user restores, you will determine if the SKPaymentTransaction's originalTransaction's transactionIdentifier matches the custom account. If not, then you can assume this is a different user. You can read more about that here:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Restoring.html

Note that the receipt contains a field called the original transaction id. This is what you would use for subscriptions to track the original transaction id. This is because each time you auto renew, a new transaction id will be generated for the auto renew. The receipt will actually contain all the purchases.

On your server, you would want to save the original transaction id and potentially the receipt. Essentially the more metadata your store around this, the better off you will be if you have to do any form of double checking transactions.

Mobile Ben
  • 7,121
  • 1
  • 27
  • 43