Skip to content

Obsoleted Purchases.createAlias/identify/reset and simplified IdentityManager implementation#974

Merged
taquitos merged 3 commits into
RevenueCat:mainfrom
NachoSoto:identity-manager-configure-idempotent
Nov 30, 2021
Merged

Obsoleted Purchases.createAlias/identify/reset and simplified IdentityManager implementation#974
taquitos merged 3 commits into
RevenueCat:mainfrom
NachoSoto:identity-manager-configure-idempotent

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

Fixes #732. Instead of worrying about whether IdentityManager.configure was idempotent or if the implementation was correct, I realized that Purchases never called that method after its initialization
Therefore, to simplify the whole implementation, the configure part is now in the constructor. Subsequent logIn/logOut calls are the only way to change the identity.

Some of this code was tangled with some of the deprecations in IdentityManager, so to aid in this refactor, I obsoleted 3 methods that were already deprecated in version 3.13.0.

This allowed me to remove the associated tests instead of changing them to use the new API. Following #950, these methods are now separate in Obsoletions.swift, and they point to the new methods.

The remaining tests in PurchasesTests all pass, and the ones in IdentityManagerTests have been converted to initializing new IdentityManager instances. Those pass as well, so I feel confident in this refactor 💪

@NachoSoto NachoSoto requested review from a team, aboedo and taquitos November 19, 2021 00:19
@NachoSoto NachoSoto force-pushed the identity-manager-configure-idempotent branch from 17590e8 to 046acfc Compare November 19, 2021 00:42
@NachoSoto

NachoSoto commented Nov 19, 2021

Copy link
Copy Markdown
Contributor Author

I removed the calls to these methods from SwiftAPITester, but this has exposed an issue: Objective-C is able to call them!
Probably because they're obsoleted like this:

@available(swift, obsoleted: 1, ...)

I'm going to fix this for all methods in Obsoletions.swift, otherwise Objective-C users can call this with only a warning, but it would result in a fatalError!

@NachoSoto

Copy link
Copy Markdown
Contributor Author

I removed the calls to these methods from SwiftAPITester, but this has exposed an issue: Objective-C is able to call them!

The right solution is to just use @available(*, unavailable, renamed: ""), the problem is that looks like there's no way to specify a different new method name for Obj-C and Swift. I haven't had to deal with this in the past (I haven't really touched Obj-C in years). @taquitos / @aboedo any guidance here?

@aboedo

aboedo commented Nov 19, 2021

Copy link
Copy Markdown
Member

🤔 I think you might still be able to obsolete them by instead of marking swift, marking all platforms, i.e.:

@available(iOS, obsoleted: 1, renamed: "getCustomerInfo(completion:)")
@available(tvOS, obsoleted: 1, renamed: "getCustomerInfo(completion:)")
@available(watchOS, obsoleted: 1, renamed: "getCustomerInfo(completion:)")
@available(macOS, obsoleted: 1, renamed: "getCustomerInfo(completion:)")
@objc func purchaserInfo(completion: @escaping (CustomerInfo?, Error?) -> Void) {

@NachoSoto

Copy link
Copy Markdown
Contributor Author

That's essentially the same as unavailable: https://nshipster.com/available/
Since we're making them unavailable for all versions, I think it's more precise.

But regardless, I'm still unsure about the renamed: value: should that point to the Obj-C parameter name? I'm not sure if Xcode parses that and converts it to Swift automatically?

@aboedo

aboedo commented Nov 19, 2021

Copy link
Copy Markdown
Member

testing it out locally it seems to correctly identify the objc name, but it doesn't suggest an automatic fix for objc
image

@NachoSoto

Copy link
Copy Markdown
Contributor Author

So I guess that's always been an issue? Should we just have the swift name in rename: then?

@aboedo

aboedo commented Nov 19, 2021

Copy link
Copy Markdown
Member

to clarify, the thing that I tested out locally was specifying all platforms separately instead of swift. When I tried with just swift, it let me call the method just fine in objc

@NachoSoto

NachoSoto commented Nov 19, 2021

Copy link
Copy Markdown
Contributor Author

Right, thanks for checking that :)
I'm waiting to see if somebody on Twitter has an answer about providing different names. As to how to obsolete them I don't have a preference :) I just think that 1 line of @available(*, unavailable) is simpler than 4, but either way we have the name issue.

@NachoSoto

Copy link
Copy Markdown
Contributor Author

I fixed this in #981.

NachoSoto added a commit to NachoSoto/purchases-ios that referenced this pull request Nov 20, 2021
…ective-C

See discussion in RevenueCat#974.
Since they were only marked as `obsoleted` for Swift, Objective-C was able to call them.
@NachoSoto NachoSoto force-pushed the identity-manager-configure-idempotent branch from 3e77b32 to 93e7f1d Compare November 20, 2021 23:17
@NachoSoto

Copy link
Copy Markdown
Contributor Author

This branch is ready, but per my conversation with @aboedo, waiting to hear from the support team to make sure it's not too premature to deprecate these methods.

@NachoSoto NachoSoto added the status: waiting-for-reply Issues that are waiting for a reply label Nov 20, 2021
Comment thread Purchases/Misc/Obsoletions.swift Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a message to all these fatalError()s like reset obsoleted, please use logOut

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is unreachable, it's impossible to call it 😛

@stale stale Bot removed the status: waiting-for-reply Issues that are waiting for a reply label Nov 22, 2021

@taquitos taquitos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending support's input, I like this very much 😺

@NachoSoto NachoSoto force-pushed the identity-manager-configure-idempotent branch from 93e7f1d to 135c711 Compare November 27, 2021 03:09
@NachoSoto NachoSoto added the status: waiting-for-reply Issues that are waiting for a reply label Nov 27, 2021
…yManager implementation

Fixes RevenueCat#732. Instead of worrying about whether `IdentityManager.configure` was idempotent or if the implementation was correct, I realized that `Purchases` never called that method after its initialization
Therefore, to simplify the whole implementation, the `configure` part is now in the constructor. Subsequent `logIn`/`logOut` calls are the only way to change the identity.

Some of this code was tangled with some of the deprecations in `IdentityManager`, so to aid in this refactor, I `obsoleted` [3 methods that were already `deprecated` in version 3.13.0](https://github.com/RevenueCat/purchases-ios/blob/3.13.0/Purchases/Public/RCPurchases.h#L205-L224).

This allowed me to remove the associated tests instead of changing them to use the new API. Following RevenueCat#950, these methods are now separate in `Obsoletions.swift`, and they point to the new methods.

The remaining tests in `PurchasesTests` all pass, and the ones in `IdentityManagerTests` have been converted to initializing new `IdentityManager` instances. Those pass as well, so I feel confident in this refactor 💪
@NachoSoto NachoSoto force-pushed the identity-manager-configure-idempotent branch from 135c711 to af1f3a0 Compare November 29, 2021 23:05
@stale stale Bot removed the status: waiting-for-reply Issues that are waiting for a reply label Nov 29, 2021
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Just to confirm @taquitos, you're good if we merge this now? :)

@taquitos

Copy link
Copy Markdown
Contributor

@NachoSoto let's merge to help unblock other PRs. We can undo this if we get feedback that suggests it's not the right move.

@taquitos taquitos merged commit eaf1244 into RevenueCat:main Nov 30, 2021
@NachoSoto NachoSoto deleted the identity-manager-configure-idempotent branch November 30, 2021 00:09
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Great thanks!

NachoSoto added a commit that referenced this pull request Nov 30, 2021
Fixes [sc-10159].

Based on top of #974 because it contains a significant simplification of `IdentityManager` that makes this a lot easier.

Note that `Purchases.logIn` will still fail with an error when trying to use an empty string. This PR does not change that behavior.
@aboedo

aboedo commented Nov 30, 2021

Copy link
Copy Markdown
Member

@NachoSoto @taquitos let's reflect this in our v4 migration guide in that case.

Shortcut link: https://app.shortcut.com/revenuecat/story/11512/update-migration-guide-to-include-removal-of-identity-v2

@NachoSoto

Copy link
Copy Markdown
Contributor Author

@aboedo added here: #1010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Early return from configure call

3 participants