Skip to main content

The scenario is someone makes a purchase without an apple login so I see the subscription in the sandbox with an anonymous ID. 

Then they log in using sign in with apple. Since I now have the user ID I log in to RevenueCat with the new ID assuming it will be associated with the anonymous ID and the purchasing info returned will say the subscription is active. It doesn’t do the association and the entitlements are empty.

  func handle(_ authResult: Result<ASAuthorization, Error>) {
print("Authorization HANDLE")

switch authResult {

case.success(let auth):
Logger.su.info("Authorization successful: \(auth)")

switch auth.credential {

case let credential as ASAuthorizationAppleIDCredential:
Logger.su.info("Authorization credential: \(credential) user:\(credential.user)")

Purchases.shared.logIn(credential.user) { (purchaserInfo, created, error) in

if let error = error {
Logger.pay.error("PurchaseViewModel:login:error:\(error.localizedDescription)")
}
else {
Logger.pay.error("PurchaseViewModel:login:succeeded:purchaserInfo:\(purchaserInfo.debugDescription)")
}

let subscription_active = purchaserInfo?.entitlementsnRevenueCatConstants.entitlementID]?.isActive == true

Task {
LoginManager.shared.handleSignIn(credential: credential)
}

onboarding.nextAfterLogin(isSubscriptionActive: subscription_active)
}

default:
Logger.su.info("Authorization default credential: \(auth.credential.description)")
}

Should this work? I need to do this logic here, so I know if a paywall should be displayed next if they don’t have an active subscription. Or should I do a restore transaction?

Your code looks good.  

Since I now have the user ID I log in to RevenueCat with the new ID assuming it will be associated with the anonymous ID and the purchasing info returned will say the subscription is active.

Yes, on a high level this is how it should work, but it's a little more complicated than that. See here our documentation for how this works: https://www.revenuecat.com/docs/user-ids#login-method-alias-behavior 

The problem here is a little broad for me to give you a precise answer – for a more detailed response, it’d be helpful to have a RC user id or some logs for what you are seeing, and to know what you are expecting vs what you are getting. It would be helpful if you opened a ticket so I can look more in depth into this for you.


It’s more about how to properly handle all the possible out-of-order process flows than things not working.

Just logging in to revenuecat doesn’t seem to do anything, so…

If there’s a subscription already active on an anonymous ID I log in to revenuecat, and when that returns, I restore transactions.

If there’s an active subscription on a real user ID then I log in to revenuecat. 

If there’s no active subscription, I log in to revenuecat.

This seems to work. 


If there’s a subscription already active on an anonymous ID I log in to revenuecat, and when that returns, I restore transactions.

Yes, you want to login and then restore purchases to associate these transactions.

 

If there’s an active subscription on a real user ID then I log in to revenuecat. If there’s no active subscription, I log in to revenuecat.

Yes, you are correct. 


Reply