robotmedia / RMStore

A lightweight iOS library for In-App Purchases
Apache License 2.0
2.42k stars 450 forks source link

Will disconnect from keychain mean purchases can't be restored? #221

Open inPhilly opened 6 years ago

inPhilly commented 6 years ago

I have to change the prefix for my AppID to my Team AppID's prefix. But according to this technical document, this is going to cause issues for apps that use Keychain:

https://developer.apple.com/library/archive/technotes/tn2311/_index.html

A one-time loss in keychain data will occur if you switch your App ID prefix

For apps utilizing the Keychain Services APIs, changing the App ID prefix of an existing app will have implications for your app that you should be aware of.

Every keychain item in iOS contains an attribute called the keychain access group. An iOS app can only access those keychain items it has permission to. This permission comes from the code signing entitlements stamped into the app when it is signed (using your current App ID prefix).

iOS has one keychain and one keychain only. Access to individual items is gated by their access group.

By default, an app can only access keychain items with the keychain access group matching the application-identifier code signing entitlement. However, if you would like to share keychain items amongst your apps, you can add a custom keychain-access-group code signing entitlement that specifies an array of keychain access groups that the app can access. However, if your app is using one or more custom keychain-access-groups, then if you change your App ID prefix all of your custom keychain-access-groups will be orphaned and you will no longer be able to access them.

This may have only minor implications in some cases. For example, if your keychain usage is modest it might not be a big deal for you to make a change: apps that simply store a user password in the keychain for convenience, may decide to change their App ID prefix to their Team ID based App ID prefix at the small cost of requiring the user to re-enter their password one more time.

I don't really understand much about Keychain, but I know that RMStore uses it, and my app uses RMStore, and when the AppID prefix is changed, it will change all apps that have already been deployed.

I know this isn't an issue so much as begging for someone to help me, but I can't figure out if changing the AppID prefix will cause the app to crash because of RMStore, or if the purchases won't be able to be restored, or if something else terrible will happen. If anyone at all has any idea what this code is doing with Keychain and what the consequences will likely be of 'A one-time loss in keychain data', I would appreciate so much if you could share any insights with me. Thanks in advance to anyone who is moved to answer - I am a lone developer with no one to ask questions of, and I am really hurting with this right now.

Theome commented 6 years ago

RMStore can save transactions in the keychain (see Transaction Persistence). If you use RMStore's Transaction Persistence to save and restore information about in-app purchases, this information will be lost if you change the App ID prefix.

This is not a problem if you have in-app purchases that can also be restored from the App Receipt, like non-consumables or auto-renewing subscriptions. Users can then use your "Restore purchases" functionality to restore previous purchases in your app. This will continue to work even with a new App ID prefix.

If your app offers in-app purchases whose transactions are not kept in the App Receipt (e.g. consumables), and you use Transaction Persistence to keep a record of these transactions, these transactions will be lost if you change the App ID prefix.

I wouldn't expect RMStore to crash or otherwise malfunction just by changing the App ID prefix.