iOS Question Code to check active subscription

toro1950

Active Member
Licensed User
Hi, I'm having trouble testing my app subscription through RevenueCat. I'm not sure which code is the correct one for these two.
If Main.HasPremium Then or If Success Then
If I test with Main.HasPremium it tells me that the subscription is not active, if I test with Success it tells me that it is active

B4X:
PurchaseHelper.Initialize(Me,"PurchaseHelper",m_API_KEY)
    PurchaseHelper.ProductIndentififer = Array As String("Mesi12") 'The Product identifyer
        Wait For (PurchaseHelper.CheckPurchases) complete (Success As Boolean)
    If Main.HasPremium Then
    If Success Then
I have a doubt about the code, because in the example
I downloaded, the same code is used to display the existing subscription.

B4X:
B4XPages.SetTitle(Me,"RevenueCat Example")
    
    PurchaseHelper.Initialize(Me,"PurchaseHelper","YourRevenueCatApiKey")
    PurchaseHelper.ProductIndentififer = Array As String("all_access_1_month_lognote","all_access_1_year_lognote") 'The Product identifyer
    
    Wait For (PurchaseHelper.CheckPurchases) complete (Success As Boolean) 'Must be called at app start, as we check here whether the user has the Premium version
    Log("Do I have a premium version? " & Success)
    
    Wait For (PurchaseHelper.GetProductsInformation(PurchaseHelper.ProductIndentififer)) complete (lstPurchases As List)
    
    For Each ProductInfo As ProductInformation In lstPurchases
        'Log(ProductInfo.Tag)
        'Log(ProductInfo.Description)   
        CustomListView1.AddTextItem(ProductInfo.Title & " - " & ProductInfo.LocalizedPrice,ProductInfo.ProductIdentifier)   
    Next
So I'm asking for clarification on the correct code to verify that the subscription is active.
I'm hoping someone can help me, I made another post about RevenueCat a while ago with no response,
I don't think anyone uses RevenueCat or is there another way to do it?
 

Alexander Stolte

Expert
Licensed User
Longtime User
The confusion: Success is just the return value of CheckPurchases, which always returns True (it only indicates the function completed, not the subscription status).

The correct way: Use Main.HasPremium to check the actual subscription status.
B4X:
Wait For (PurchaseHelper.CheckPurchases) complete (Success As Boolean)
If Main.HasPremium Then
    Log("User has active subscription")
Else
    Log("No active subscription")
End If

Why it might show "not active" during testing:
  1. Sandbox vs Production: Make sure you're using the correct RevenueCat API key (check if it's the public SDK key, not the secret key)
  2. Product Identifier mismatch: Your product identifier "Mesi12" must exactly match what's configured in RevenueCat dashboard
  3. User ID: RevenueCat tracks subscriptions per user. If you're testing with different user IDs, the subscription won't carry over
  4. Cache issue: The helper caches the expiration date in KeyChain. For testing, you can try clearing the cache:
B4X:
p.KeyChainPut("RevenueCat_SubscriptionExpiresDate","")

5. Check the logs: Add this after CheckPurchases to debug:
B4X:
Log("HasPremium: " & Main.HasPremium)
Log("Expiry: " & p.KeyChainGet("RevenueCat_SubscriptionExpiresDate"))
 
Upvote 0

toro1950

Active Member
Licensed User
Alexander, thank you for your reply, but something still doesn't make sense to me. I use Main.HasPremium and responds that it is not active,
the variable Mod3.VAB is false, I call the sub from the sub B4XPage Appear

B4X:
private Sub contpagato
    PurchaseHelper.Initialize(Me,"PurchaseHelper",m_API_KEY)
    PurchaseHelper.ProductIndentififer = Array As String("Mesi12") 'The Product identifyer
    
    Wait For (PurchaseHelper.CheckPurchases) complete (Success As Boolean) 
    
    If Main.HasPremium=True Then
        Mod3.VAB=True
        Return
    Else
       Mod3.VAB=False
      B4XPages.ShowPage("page2")
    (where do I make the purchase)
      End If
      
End Sub
that's what I call the purchase sub in Page 2 where I have a panel showing the features and type of subscription

B4X:
PurchaseHelper.Initialize(Me,"PurchaseHelper",m_API_KEY)
    PurchaseHelper.ProductIndentififer = Array As String("Mesi12") 'The Product identifyer
    Wait For (PurchaseHelper.RequestPayment("Mesi12")) Complete (Success As Boolean)
        
    If Success Then
But as a response it tells me that I already have a subscription, see attached image
 

Attachments

  • image1.png
    image1.png
    411.8 KB · Views: 0
Upvote 0
Top