1 Reply
      Latest reply on Mar 15, 2019 1:11 PM by PBK
      apple.ua Level 1 Level 1 (0 points)

        Hi everyone. I am now testing in-app purchases within my app. I've ran into a problem when user purchases 1 month subscription (which lasts for 3 minutes in sandbox) and then after 3 minutes my app locks premium features if app is opened and actively used. I decide if premium features should be unlocked by retrieving expiration date of subscription and comparing it to now. This does not happen if I restart the app because then StoreKit completes pending renewal transactions in didFinishLaunchingWithOptions. Yes, the isPremium variable is checking for expiry date every time it's being accessed via getter. Should I decide isPremium state once in didFinishLaunchingWithOptions after pending transactions complete?

        But what if app is not "unloaded" from memory for a long time? Then isPremium will be true unless app restarts.

        Maybe I can put StoreKit's complete transactions in applicationDidBecomeActive? Though in every guideline they say it should be in didFinishLaunchingWithOptions. Or maybe I have another flaw in my in-app purchases design? Thank you.

        • Re: What happens if subscription [auto-renewable] cycle happens while app is running
          PBK Level 7 Level 7 (3,105 points)

          When an app is first opened it executes didFinishLaunchingWithOptions. Unless there is a problem with available memory, when it is closed it goes into background and then when it is reopened it does not execute didFinishLaunchingWithOptions but rather applicationWillEnterForeground and various other methods.  So, if you remove the transaction observer and, perhaps, deallocate StoreKit methods, you need to add a transaction observer and re class StoreKit methods when your app both enters foreground and also when it launches.  The 'best practice' suggestion from Apple is to always leave an observer available so that a new subscription will call updatedTransactions whenever the app is open.   Alternatively, you could add the transaction observer whenever the app enters foreground (or launches) provided your app believes the subscription may have expired.  I think that's 'better practice'.