Skip to content

Commit

Permalink
fix: send native to flutter messages on main thread (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
levibostian authored Aug 1, 2024
1 parent 02dfe93 commit bc8704b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ios/Classes/SwiftCustomerIoPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,18 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin {
DispatchQueue.main.async {
MessagingInApp.shared.initialize(eventListener: CustomerIOInAppEventListener(
invokeMethod: {method,args in
self.invokeMethodInBackground(method, args)
self.invokeMethod(method, args)
})
)
}
}

func invokeMethodInBackground(_ method: String, _ args: Any?) {
DispatchQueue.global(qos: .background).async {
func invokeMethod(_ method: String, _ args: Any?) {
// When sending messages from native code to Flutter, it's required to do it on main thread.
// Learn more:
// * https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading
// * https://linear.app/customerio/issue/MBL-358/
DispatchQueue.main.async {
self.methodChannel.invokeMethod(method, arguments: args)
}
}
Expand Down

0 comments on commit bc8704b

Please sign in to comment.