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

In-App Messaging Crash - main thread must be used #161

Closed
djw27 opened this issue Jul 6, 2023 · 1 comment · Fixed by #165
Closed

In-App Messaging Crash - main thread must be used #161

djw27 opened this issue Jul 6, 2023 · 1 comment · Fixed by #165

Comments

@djw27
Copy link

djw27 commented Jul 6, 2023

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 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
Screenshot 2023-07-06 at 11 04 28

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.

func screen(name : String, data : Dictionary<String, AnyHashable>?) -> Void {
...
  DispatchQueue.main.async {
    CustomerIO.shared.screen(name: name)
  }
...
}

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?

@djw27 djw27 changed the title In-App Messaging Crash - In-App Messaging Crash - main thread must be used Jul 6, 2023
@Shahroz16
Copy link
Contributor

Hey @djw27, thank you for reporting this. We are having a look into this and will report back with the findings. Apologies for inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants