Coder Social home page Coder Social logo

Comments (5)

russell-archer avatar russell-archer commented on June 6, 2024

Sorry for the delay in replying - been on a short vacation!
Re your issue, I'm certain that StoreHelper does (or did) pick up subscription cancellations correctly. It's possible I've done something to break it, but I'll take a look and let you know.

from storehelper.

russell-archer avatar russell-archer commented on June 6, 2024

Yes, you're right. Cancellations are not being correctly picked up. I'll put out a fix asap!

from storehelper.

ashayk avatar ashayk commented on June 6, 2024

Hi Russel, thanks for picking it up. Sorry to bother you post-holiday :). Generally speaking, I've been finding using currentEntitlements() with requestProductsFromAppStore() to give a pretty reliable result. Eventually, things are updated or timed out in such a way that the Product returned is nil once expired. Hope that helps a bit.

Thanks,

--Alex

from storehelper.

russell-archer avatar russell-archer commented on June 6, 2024

I've added a few things to help with the situation where subscriptions are renewed or expire when the app's not running.
See AppStoreHelper.paymentQueue(_:updatedTransactions:) and StoreHelper.handleStoreKit1Transactions(productId:status:transaction:).

From the research I've done, it looks like when using Xcode StoreKit Testing and Sandbox Testing subscription renewal transactions that happen when the app's not running are NEVER picked up by StoreKit2! That is, the transactions don't appear in StoreKit.Transaction.all or Transaction.currentEntitlement(for:). This seems to have been a known issue since the release of StoreKit2. So, you can have situations where a user has paid to renew their subscription but StoreKit2 has no knowledge of it. However, this only seems to affect Xcode StoreKit testing and sandbox testing. Production builds using the live App Store DO NOT appear to suffer from this issue.

That's great, but you really want to be convinced during testing that your app works correctly! So, as a workaround, StoreHelper now maintains a transactionUpdateCache that keeps track of subscription transactions that happen when the app's not running. This cache is used in isPurchased(productId:) when a call to Transaction.currentEntitlement(for: productId) returns nil.

from storehelper.

ashayk avatar ashayk commented on June 6, 2024

Thanks Russel. Can confirm that's working nicely now. FWIW, I'd found a decent workaround by introspecting currentEntitlements. That seemed to work in the Debugger, etc... Eventually, entitlements would be updated, but likely not in the background as you've mentioned, so you do have to be more generous in checking subscription status. That is, not simply relying on the state at the very beginning of app execution. The following code was working consistently via an extension on StoreHelper...

public func purchasedSubscription() async -> Product? {

    if self.hasStarted == false {
        await self.start()
    }
    
    let result : Set<ProductId> = await self.currentEntitlements()
    guard let productId = result.first else {
        return nil
    }
    
    guard let products : [Product] = await self.requestProductsFromAppStore(productIds: [productId]) else {
        return nil
    }
    guard let product = products.first else {
        return nil
    }
   
   return product
}

from storehelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.