Describe the bug
With in-app messaging enabled & with page rules setup as the trigger for displaying the in-app message, the app crashes when trying to show the in-app message.
When logging screen views with customerio, i.e. cio.screen('ScreenName') we're doing so on a background thread. When this eventually calls through to setCurrentRoute of Gist and ultimately invokes a MessageManager which tries to initialise a WKWebView we get the error -[WKWebView .cxx_construct] must be used from main thread only.
To Reproduce
Create an in-app message in customerio with a page rule trigger
Setup the app to log screen views with .screen()
Visit the screen in the app that matches the page rule trigger
App crashes
Screenshots
Additional context
I can see that the library makes use of DispatchQueue.main.async to execute tasks on the main thread when initializing the library and registering for push notifications.
I can verify that wrapping the main CustomerIO.shared.screen(name: name) call with this 'fixes' the problem, i.e.
To be a bit more specific, the following also works by overriding specifically where we bridge from customerio -> Gist:
extension MessagingInAppImplementation: ScreenTrackingHook {
public func screenViewed(name: String) {
logger.debug("setting route for in-app to \(name)")
DispatchQueue.main.async {
self.inAppProvider.setRoute(name)
}
}
}
I'm not sure on the implications of this as a solution, though. Thoughts? I would have thought that this issue would be impacting everyone trying to use in-app messaging so a little surprised it hasn't been raised before, unless we're doing something obviously incorrect?
SDK version: 2.4.2
Environment: Development
Describe the bug With in-app messaging enabled & with page rules setup as the trigger for displaying the in-app message, the app crashes when trying to show the in-app message.
When logging screen views with customerio, i.e.
cio.screen('ScreenName')
we're doing so on a background thread. When this eventually calls through tosetCurrentRoute
of Gist and ultimately invokes aMessageManager
which tries to initialise aWKWebView
we get the error-[WKWebView .cxx_construct] must be used from main thread only
.To Reproduce
.screen()
Screenshots
Additional context I can see that the library makes use of
DispatchQueue.main.async
to execute tasks on the main thread when initializing the library and registering for push notifications.I can verify that wrapping the main
CustomerIO.shared.screen(name: name)
call with this 'fixes' the problem, i.e.To be a bit more specific, the following also works by overriding specifically where we bridge from customerio -> Gist:
I'm not sure on the implications of this as a solution, though. Thoughts? I would have thought that this issue would be impacting everyone trying to use in-app messaging so a little surprised it hasn't been raised before, unless we're doing something obviously incorrect?