Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit be3a1d5

Browse files
dasMajoMax
authored andcommitted
iOS11 WKWebView Crashfix (#280)
1 parent 9cf52f1 commit be3a1d5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ios/CodePushReportingManager.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ + (void)reportStatus:(StatusReport*)statusReport withWebView:(UIView*)webView {
3535
/* JS function to call: window.codePush.reportStatus(status: number, label: String, appVersion: String, deploymentKey: String) */
3636
NSString* script = [NSString stringWithFormat:@"document.addEventListener(\"deviceready\", function () { window.codePush.reportStatus(%i, %@, %@, %@, %@, %@); });", (int)statusReport.status, labelParameter, appVersionParameter, deploymentKeyParameter, lastVersionLabelOrAppVersionParameter, lastVersionDeploymentKeyParameter];
3737
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
38-
[webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:script withObject: NULL];
38+
// The WKWebView requires JS evaluation to occur on the main
39+
// thread starting with iOS11, so ensure that we dispatch to it before executing.
40+
dispatch_async(dispatch_get_main_queue(), ^{
41+
[webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:script withObject: NULL];
42+
});
3943
} else if ([webView isKindOfClass:[UIWebView class]]) {
4044
// The UIWebView requires JS evaluation to occur on the main
4145
// thread, so ensure that we dispatch to it before executing.

0 commit comments

Comments
 (0)