A toot by my pal Casey introduced again some irritating reminiscences about expired subscriptions that haven’t expired (sure, actually). This weblog put up will hopefully aid you keep away from having these identical recollections.
All of it begins when a buyer contacts you with a screenshot that appears one thing like this:
Your code and the App Retailer don’t agree about when a subscription expired. The reason for that is Apple’s StoreKit pattern code. It’s possible that you’ve some code just like line 246 of Retailer.swift:
subscriptionGroupStatus = strive? await subscriptions.first?.subscription?.standing.first?.state
That code will work wonderful till you encounter a buyer that has Household Sharing enabled, as most do. The problem is that the Product.SubscriptionInfo can include a number of gadgets, and the code above solely checks the primary one.
How can that occur? With Household Sharing, the people who find themselves utilizing the subscription act independently: one could subscribe for a 12 months after which cancel. Then one other may subscribe at a later date for less than a month. You need to test the entire subscriptions, not simply the primary one. One thing like this:
if let statuses = strive? await subscriptions.first?.subscription?.standing {
let checkStatus = statuses.first $0.state == .inGracePeriod
…
}
The documentation and pattern code doesn’t say it, so I’ll: Apple’s StoreKit pattern doesn’t help Household Sharing.
In the event you’re searching for code from Apple that does help Household Sharing, you’ll find it buried in one of many WWDC demo apps. Clearly.
What’s most irritating about this case is that it exists for those who’ve learn the documentation:
The array can have multiple subscription standing in case your subscription helps Household Sharing. Present the shopper with service for the subscription based mostly on the best degree of service the place the state is subscribed.
Which is mindless till you’ve learn the paragraphs above.
Truly, I used to be incorrect. Probably the most irritating factor about this case is that it’s basically untestable. You possibly can’t reproduce the issue, even after a buyer lets they’re having points and also you’ve learn this weblog put up. That’s as a result of there may be:
No method to check this in Xcode (even when it’s turned on in .storekit configuration).No method to check this in TestFlight (pretend purchases don’t use Household Sharing).No affordable method to check this in manufacturing (pink flags shall be raised with refunding and altering purchases repeatedly whereas testing with actual Apple IDs).
The StoreKit check harness in Xcode has been a godsend, however on this case it’s simply lower than the duty. And the result’s a number of pissed off builders who’re testing code in manufacturing on a buyer’s gadget.
Apple people: you’ll be able to study extra in FB13212468. It’s been closed as “Investigation full” — perhaps you must ask Casey if he agrees with that decision.