Skip to content

Purchases: avoid potential crash when initializing in the background#2231

Merged
NachoSoto merged 2 commits into
mainfrom
purchase-initialization-crash
Jan 18, 2023
Merged

Purchases: avoid potential crash when initializing in the background#2231
NachoSoto merged 2 commits into
mainfrom
purchase-initialization-crash

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

#2224 likely fixes #1877. This change also avoids running the code being triggered in that crashing stack trace, since it's not necessary.
Purchases.delegate setter already calls sendCachedCustomerInfoToDelegateIfExists, so that method was unnecessary. Removing this call to sendCachedCustomerInfoIfAvailable doesn't make any test fails because of that.

This behavior is also verified by PurchasesConfiguringTests: testFirstInitializationFromBackgroundCallsDelegateForAnonIfInfoCached and testSettingTheDelegateAfterInitializationSendsCachedCustomerInfo.

I also improved this by extracting it into its own method and adding an explanation for the isApplicationBackgrounded check.

@NachoSoto NachoSoto added the pr:fix A bug fix label Jan 18, 2023
@NachoSoto NachoSoto requested a review from a team January 18, 2023 19:41
@NachoSoto NachoSoto mentioned this pull request Jan 18, 2023
5 tasks
#2224 likely fixes #1877. This change also avoids running the code being triggered in that crashing stack trace, since it's not necessary.
`Purchases.delegate` setter already calls `sendCachedCustomerInfoToDelegateIfExists`, so that method was unnecessary. Removing this call to `sendCachedCustomerInfoIfAvailable` doesn't make any test fails because of that.

This behavior is also verified by `PurchasesConfiguringTests`: `testFirstInitializationFromBackgroundCallsDelegateForAnonIfInfoCached` and `testSettingTheDelegateAfterInitializationSendsCachedCustomerInfo`.

I also improved this by extracting it into its own method and adding an explanation for the `isApplicationBackgrounded` check.
@NachoSoto NachoSoto force-pushed the purchase-initialization-crash branch from 2811150 to fdfd257 Compare January 18, 2023 22:54
@NachoSoto NachoSoto merged commit 197ef28 into main Jan 18, 2023
@NachoSoto NachoSoto deleted the purchase-initialization-crash branch January 18, 2023 23:21
NachoSoto pushed a commit that referenced this pull request Jan 19, 2023
**This is an automatic release.**

### Bugfixes
* `Purchases`: avoid potential crash when initializing in the background
(#2231) via NachoSoto (@NachoSoto)
### Other Changes
* `PurchaseTester`: ignore errors when restoring purchases (#2228) via
NachoSoto (@NachoSoto)
* `PurchaseTester`: fixed `isPurchasing` state when purchasing fails
(#2229) via NachoSoto (@NachoSoto)
* `PurchaseTester`: setting `changelog` when submitting to `TestFlight`
(#2232) via NachoSoto (@NachoSoto)
* Revert "`SPM`: added `APPLICATION_EXTENSION_API_ONLY` flag to
`RevenueCat` and `ReceiptParser` (#2217)" (#2225) via NachoSoto
(@NachoSoto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in CustomerInfoManager

2 participants