Call the completion handler on the main thread #549
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
I don't have access to GitHub issues for this repo, but I have created an official support ticket with reference number 45249 by contacting Checkout's support email.
Proposed changes
This fixes a crash when using the Frames iOS SDK in a SwiftUI app by wrapping the returned
UIViewController
fromPaymentFormFactory.buildViewController(configuration:style:completionHandler:)
in a SwiftUIUIViewControllerRepresentable
.Test Steps
I created a small Xcode project to reproduce the issue (Xcode 16.2):
FramesCheckoutTestSwiftUI.zip
If you don't have Xcode 16.2 installed try setting the minimum iOS target to 18.0 or 18.1.
You can verify this issue is fixed by tapping the Pay button on the payment form and observing that no crash occurs and the
completionHandler
is running successfully.Checklist
Further comments
The crash that was occurring on line 185 of DefaultPaymentViewModel was EXC_BREAKPOINT and was occurring on a thread other than the main thread. For some reason this was not an issue when the client integrating this library uses UIKit. This issue only surfaces when attempting to integrate the library on a SwiftUI app. In both cases, I think it's incorrect to complete outside the main thread. So I added the fix.
I also digged a little deeper in the call stack trace and noticed that this issue might be fixed in
CheckoutAPIService
(by callingcompletion
forCheckoutAPIService.callRiskSDK(tokenDetails:completion:)
on the main thread, but sinceCheckoutAPIService
is not directly related or responsible for UI, I think it doesn't need to run on the main thread.I don't have enough experience with the source code to write a unit test to test for this specific scenario (make sure the completionHandler is always running on the main thread). If you can guide me or add to this pull request yourself, I would appreciate that!