AppStore.manageSubscriptionsSheet and the main thread #3331
seanmrich
started this conversation in
Show and tell
Replies: 2 comments 3 replies
-
Hi @seanmrich, thanks for sharing! It seems quite strange for |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was having an issue using SwiftUI's
AppStore.manageSubscriptionsSheet(isPresented:subscriptionGroupID:)
provided by StoreKit. The underlying sheet logic accesses the binding on a background thread. This brings up a purple runtime warning from TCA about interacting with aStore
when not on the main thread. Thank goodness for this warning because I wouldn't have expected this to happen on a background thread.Here's my setup. I added an item to my destination enum and a computed property to my
State
to accommodate theisPresented
parameter.Then I included the modifier in my view.
I used
assert(Thread.mainThread)
in theshowManageSubscriptions
property to verify both the get and set were being called on a background thread. To get around this, I took over the binding logic myself by wrapping the UIKit version of the api which is theshowManageSubscriptions(in:subscriptionGroupID:)
method.This method avoids the main thread issue and also presents a more TCA-friendly interface that avoids the computed property in
State
.Beta Was this translation helpful? Give feedback.
All reactions