I have an APP. After User A (Apple ID) subscribes, the user switches to User B (Apple ID) in the App Store. I want to cancel the subscription. If the user switches back to User A (Apple ID) in the App Store, I want to restore the subscription. How can I achieve this? According to the official documentation, it is not recommended to call the restore function frequently.
App Store user switching, canceling App subscription
Hello!
Once subscribed, users can cancel their subscription via Manage Subscriptions. Users might be using their Apple Account on different devices and/or might want to preserve their access to the service on that Apple Account. No need to cancel subscription on user's behalf. If you plan to restrict access depending on Apple Account signed in to the device, make sure to let users know, that is not a common practice.
You should always be checking status of user's subscription and only grant access to what they are entitled to, and Apple Account itself is not necessarily of a concern - only subscription entitlement status. And if you have an app account system of your own, you don't need to rely on device state.