Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed concurrency issue on iOS. #413

Merged
merged 1 commit into from Mar 22, 2023
Merged

Fixed concurrency issue on iOS. #413

merged 1 commit into from Mar 22, 2023

Conversation

OctavianLfrd
Copy link
Contributor

The productsRequest method as per Apple docs can be called on any thread (source: https://developer.apple.com/documentation/storekit/skproductsrequestdelegate (please check text in read)).
Working with validProducts on such thread can cause concurrency issues, such as this one:
"Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection <__NSArrayM: 0x283ca4090> was mutated while being enumerated.'"**

Moreover, flutter results must be called on platform main thread only (source: https://docs.flutter.dev/development/platform-integration/platform-channels)
"Even though Flutter sends messages to and from Dart asynchronously, whenever you invoke a channel method, you must invoke that method on the platform’s main thread."

To fix these issues I simply wrapped all the code in dispatch_async(dispatch_get_main_queue, ^{ ... }).
Please pull this fix.

Copy link
Member

@hyochan hyochan left a comment

Choose a reason for hiding this comment

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

Great explanation! It is very clear to be merged 🎉

@hyochan hyochan added ios ios related issue bugfix labels Mar 22, 2023
@hyochan hyochan merged commit 1237aa2 into dooboolab-community:main Mar 22, 2023
1 check passed
@hyochan
Copy link
Member

hyochan commented Mar 22, 2023

5.4.1 released 🎉

JoyHong pushed a commit to JoyHong/flutter_inapp_purchase that referenced this pull request Jul 6, 2023
The `productsRequest` method as per Apple docs can be called on any
thread (source:
https://developer.apple.com/documentation/storekit/skproductsrequestdelegate
(please check text in read)).
Working with `validProducts` on such thread can cause concurrency
issues, such as this one:
**"Terminating app due to uncaught exception 'NSGenericException',
reason: '*** Collection <__NSArrayM: 0x283ca4090> was mutated while
being enumerated.'"**

Moreover, flutter results must be called on platform main thread only
(source:
https://docs.flutter.dev/development/platform-integration/platform-channels)
_"Even though Flutter sends messages to and from Dart asynchronously,
whenever you invoke a channel method, you must invoke that method on the
platform’s main thread."_

To fix these issues I simply wrapped all the code in
`dispatch_async(dispatch_get_main_queue, ^{ ... })`.
Please pull this fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix ios ios related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants