Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription Status Persistence #5

Open
simsherpa opened this issue Nov 5, 2023 · 7 comments
Open

Subscription Status Persistence #5

simsherpa opened this issue Nov 5, 2023 · 7 comments

Comments

@simsherpa
Copy link

Thank you for your very helpful review, commentary and example code for these StoreKit changes. They have been very helpful in understanding and using the new views and APIs.

One thing that is still unclear to me is if the new views, apis and .subscriptionStatusTask modifier eliminates the need to persist subscription status using AppStorage, Keychain or App Receipts. Can you share your thoughts on this?

@HuangRunHua
Copy link
Owner

Thank you for your very helpful review, commentary and example code for these StoreKit changes. They have been very helpful in understanding and using the new views and APIs.

One thing that is still unclear to me is if the new views, apis and .subscriptionStatusTask modifier eliminates the need to persist subscription status using AppStorage, Keychain or App Receipts. Can you share your thoughts on this?

In fact, these persistence methods are still useful. A simple example is, suppose there is a permanently purchased in-app purchase item such as a song. After the purchase is completed, the user can listen to the music at any time. When there is a network, your software verifies if the user purchased this music through network in the background. However, the situation is different when the user is on a plane. In theory, the user can listen to the song when there is no network, because it is a permanent purchase, but your software needs to be connected to the Internet to complete the verification. If you store the purchase results inside the software, users can also listen to the song when there is no network.

@simsherpa
Copy link
Author

Thank you. This is very helpful. Can you provide an example of how to extend the sample code you provided to persist subscription status? Ive looked at a number of tutorials for this but they are not based on the new APIs.

Also, I think I might have found a bug in the code to determine subscription status, but it's possible that I am missing something. I will file a separate issue outlining that.

Thanks again, and any suggestion on how to persist subscription status is appreciated!

@HuangRunHua
Copy link
Owner

Hi, I don't have much time recently, so for the bug review I won't regard it as the first thing but I will review it as soon as possible. You can find the official documentation and official code about SubscriptionView and StoreKit in Apple's WWDC23 sample code Backyard Birds: Building an app with SwiftData and widgets. To be honest, the sample code's subscription status won't update once expired, but it still helpful. And if you find any solution to the issue you filed please update the code and pull a request, thanks.

@simsherpa
Copy link
Author

Thanks for the follow-up. Can you explain the following statement?

the sample code's subscription status won't update once expired

Wouldn't the following ProductSubscription status function code fragment catch an expired subscription and report status as .notSubscribed ?

if case .autoRenewable = transaction.productType {
           if !(transaction.revocationDate == nil && transaction.revocationReason == nil) {
               return .notSubscribed
           }
           if let subscriptionExpirationDate = transaction.expirationDate {
               if subscriptionExpirationDate.timeIntervalSince1970 < Date().timeIntervalSince1970 {
                   return .notSubscribed
               }
           }
}

I may be misunderstanding your comment.

Thoughts?

@HuangRunHua
Copy link
Owner

I mean the code from Apple Backyard Birds: Building an app with SwiftData and widgets has one problem that I think it might be a bug. When the subscription expired, the view does not update to the not subscribed view, it still shows the last subscription plan.

@simsherpa
Copy link
Author

I see. Thank you. I'll check it out.

@HuangRunHua
Copy link
Owner

Have you check Apple's code? Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants