Solved

Randomly and false-zero-Entitlements returned from purchaseProduct:withCompletion

  • 22 October 2021
  • 69 replies
  • 926 views

Userlevel 3
Badge +8

Hi @taquitos  With the latest 4.0.0-Beta.3, the return from purchaseProduct:withCompletion can have zero entitlement even though it is not true.

I can’t reproduce while in debug mode (randomly happens outside the debugger).

Attached is a txt file with a log of successful return (I see some errors but not sure how to cancel them).

Thanks,

 

icon

Best answer by Andy 14 January 2022, 19:45

View original

69 replies

Userlevel 3
Badge +8

I am closing the issue, never been so excited about a bug being crushed. 
you guys rock. 
@Andy warm hugs 🤗 

Badge

@taquitos 

 

We are running into this issue as well. Somehow we can’t form the json response correctly.

 

```

😿‼️ Unable to instantiate SubscriberData from json object: ["original_application_version": <null>, "non_subscriptions": { }, "first_seen": 2021-12-08T21:59:55Z, "original_purchase_date": <null>, "subscriptions": { }, "other_purchases": { }, "original_app_user_id": $RCAnonymousID:c8cab3a9cb4648d8828449e29194817d, "management_url": <null>, "entitlements": { }, "last_seen": 2021-12-08T21:59:55Z]

```

Userlevel 5
Badge +8

For anyone reading this, @imougy and I had a live session and we’re currently suspecting that the underlying issue might be the change in pre-warming behavior in iOS 15, and it’s related bugs: 

 

As for ways of working around this, it seems like the suggested approach is to move the SDK configuration to the initialization of the root VC. 

I’d also advise to move related code (like reading from the keychain), for the same reason. 

It was a pleasure chatting with you @imougy! Hope this helps, and definitely let me know how it goes! 

Userlevel 3
Badge +8

I am thrilled to write this.  Since relocating the initialization to the root view controller there was zero incident of nil customerInfo.  @Andy, I can’t thank you enough for the 20 minutes code review, I wouldn’t have done it without it.

Please update the documentation to enforce this, otherwise apps will get in trouble for sure  

I will close the issue in few days, just because the majority of Stocks Live users will upgrade this week. 
@Andy and the rest of the team @cody, @taquitos, @Jacob Eiting, you guys are awesome, thank you so much for your time and experience, RevenueCat is one of the best companies I have ever worked with and of course it is because of the people and the founders. 

Userlevel 3
Badge +8

Just got those from a user with the latest 4.0.0-beta.3 

hope it give you any clue on what is happening.

the user reported that things are fine now after Restoring Purchases. 

Userlevel 3
Badge +8

Sounds great, I will let the user upgrade to iOS 15.1 and keep you in touch. 

Ok, just released Beta 5 https://github.com/RevenueCat/purchases-ios/releases/tag/4.0.0-beta.5
I think this should really help us home in on what is going on. 

Userlevel 3
Badge +8

@taquitos , Awesome, I will include it in the next update this Friday and keep you posted.

I also like to add that sometimes I get purchaserInfoWithCompletion with RCPurchaserInfo=null and it shouldn’t. 

Userlevel 3
Badge +8

Here is the error I got from the user above after installing Beta5. 
RCCustomerInfo: (null)
RevenueCat LastError: Error Domain=RevenueCat.ErrorCode Code=12 "Unable to instantiate a CustomerInfoResponse." UserInfo={readable_error_code=UNEXPECTED_BACKEND_RESPONSE_ERROR, NSUnderlyingError=0x28168af30 {Error Domain=RevenueCat.UnexpectedBackendResponseSubErrorCode Code=7 "(null)"}, NSLocalizedDescription=Unable to instantiate a CustomerInfoResponse.}

Userlevel 3
Badge +8

The user came back and mentioned he didn’t change the user ID (he changed his user name).  I confirmed that he has two devices, iPad and iPhone, both running iOS 15.1 and same version of the app, same Apple ID, on the iPhone, he can’t restore, he gets errors, on the iPad he can restore.  

Userlevel 3
Badge +8

Latest error from user (F6862686180809447439), note that CustomerInfo is nil

App:CustomerInfo: (null)RevenueCat LastError: Error Domain=RevenueCat.ErrorCode Code=12 "Unable to instantiate a CustomerInfoResponse." UserInfo={readable_error_code=UNEXPECTED_BACKEND_RESPONSE_ERROR, NSUnderlyingError=0x283ee5d10 {Error Domain=RevenueCat.UnexpectedBackendResponseSubErrorCode Code=7 "(null)"}, NSLocalizedDescription=Unable to instantiate a CustomerInfoResponse.}

 

Userlevel 3
Badge +8

Adding two more log files with detailed errors.

Guys, this issue is frustrating to everyone.  Is there a way you connect with Apple to see what is going on?  I can connect with Apple as part of my development benefits but I don’t know how to follow up if they ask detailed questions (I didn’t write the code so I have no idea what is going on)!

It is still surprising to me that not all developers having the same issue, makes me wonder if there is a best practice I need to follow?  I don’t mind sharing the code that is responsible for the integration, I know the code was working and started to break just recently but maybe this can help?  If you are interested please let me know.

 

Again, thank you and Apple really suck!

Took a little longer than expected, but here’s a new release: https://github.com/RevenueCat/purchases-ios/releases/tag/4.0.0-beta.6

We now add a lot more info to the error objects that get surfaced through the API.

Userlevel 3
Badge +8

@taquitos Sounds great, I am building now and hopefully release asap.

Userlevel 3
Badge +8

@taquitos here is the latest error attached from the same user, kind enough to keep posting us, with the latest beta.6

Today, I open the app on my device and I got no in-app at all and here is my log (Restore purchases work):-

CustomerInfo: <CustomerInfo:originalApplicationVersion=,latestExpirationDate=nil,activeEntitlements=[:],activeSubscriptions=[:],nonSubscriptionTransactions=[],requestDate=2021-11-04 16:47:10 +0000,firstSeen=2021-11-04 16:47:09 +0000,originalAppUserId=U1625795716907644928,entitlements=[:]>RevenueCat LastError: (null)
Badge

@taquitos

Is there a place in the latest sdk release that logs the json in full utf8? (We only are logging the swift dictionary object right now...)
 

The failure I have is at:

https://github.com/RevenueCat/purchases-ios/blob/aa18f434441b7e59e30a49810f0d9e3284b1873c/Purchases/Public/CustomerInfo.swift#L181


Can you also link a test project containing your deserialization test code?

Userlevel 3
Badge +8

@Winston Du good questions.  I get those logs that I posted by saving the error code in memory and when users contact me I embed those error codes so I can see what is going on.  It will be great if there is an api we call to get the internal state of the SDK so we can pass it along. 

Userlevel 5
Badge +8

@imougy update here: I found a few extensions where we’re not adding prefixes or necessarily disambiguating our extensions from others, which might cause conflicts. 

I’m going to work on an update to remove all ambiguity, which might solve it. 

Would you be willing to give it a shot when I’m done? 

Also, have you found any way to consistently reproduce this? Perhaps by changing regions on your device? 

And yes, having some information on the date extensions would be super helpful. Also, if you have any extensions on date formatters in particular, since those seemed to be the conflict with DataDog’s SDK. 

 

Userlevel 5
Badge +8

@imougy I’ve made a branch called fix/name_conflicts_on_foundation_extensions, which adds a prefix to every single internal extension in our SDK, to make absolutely sure that no conflicts can happen. 

 

If you have a way to reproduce this issue, would you mind giving the branch a shot to see if it solve it? 

Userlevel 3
Badge +8

Users have the latest iOS 15.2. I am one of them. 

Userlevel 3
Badge +8

This is awesome @Andy , thank you so much for your time and your suggestion.  I am making a release now and I feel good about it.  I am moving the initialization of the SDK to the root controller (instead of didFinishLaunchingWithOptions).

I will report back after one week to gather more data.

🙏

 

Userlevel 3
Badge +8

@taquitos If this is the case, let me break in my code and debug if any of my NSDate extensions are being called.  Do you think this is a good strategy?

Meanwhile, another log from the same user who can’t restore his purchases.

 

I think that’s a solid plan. I”ll check into this log and get back to you with anything I find.

Userlevel 3
Badge +8

@taquitos I looked at your code:-

            guard let firstSeenDateString = subscriberData["first_seen"] as? String,

                  let firstSeenDate = dateFormatter.date(fromString: firstSeenDateString) else {

                return nil

            }

            self.firstSeen = firstSeenDate

            guard let originalAppUserIdString = subscriberData["original_app_user_id"] as? String else {

                return nil

            }

After you exit with nil, you call the logger.  I can’t access the logger and pass it to you (If I can please let me know how I can ask users to do that) but the error object that I attached is the one I can pass to you.  Is there a way you can add more info there so I can pass it to you?  I debugged your code and of course I see everything fine.  

Let me know how to proceed, my NSDate extension are not being called by your sdk.

I am guessing since this is a random thing, I saw empty CustomerInfo on my device from time to time, that this is not an SDK code that is causing it, it some garbage data coming from the server.

Happy to add any info if you think of any.

 

I just merged an update that will throw errors instead of returning `nil` in https://github.com/RevenueCat/purchases-ios/pull/937

I can’t release it to Beta just yet because we also just merged a large update that includes the beginning of StoreKit2 support and we need to test it a little bit more.

There is only 1 file to update if you wanted to build the SDK from the current beta tag with this.
 

 

Reply