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

Commit

Permalink
Add flag for UIWebView usage (#588)
Browse files Browse the repository at this point in the history
* Add flag for UIWebView usage
  • Loading branch information
bbialas authored Apr 13, 2020
1 parent 2b8feca commit 9e90116
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ With the CodePush plugin installed, configure your app to use it via the followi

You are now ready to use the plugin in the application code. See the [sample applications](/samples) for examples and the API documentation for more details.

*NOTE: There is a possibility to specify WebView engine on the plugin build phase. By default UIWebView engine is used. You can force plugin to use WKWebView by adding this iOS specific preference:*
```xml
<preference name="WKWebViewOnly" value="true" />
```

## Plugin Usage

With the CodePush plugin installed and configured, the only thing left is to add the necessary code to your app to control the following policies:
Expand Down
2 changes: 1 addition & 1 deletion src/ios/CodePush.m
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ - (void)loadURL:(NSURL*)url {
// maintaining back-compat with Cordova iOS 3.9.0, we need to conditionally
// use the WebViewEngine for performing navigations only if the host app
// is running 4.0.0+, and fallback to directly using the WebView otherwise.
#ifdef __CORDOVA_4_0_0
#if (WK_WEB_VIEW_ONLY && defined(__CORDOVA_4_0_0)) || defined(__CORDOVA_4_0_0)
[self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]];
#else
[(UIWebView*)self.webView loadRequest:[NSURLRequest requestWithURL:url]];
Expand Down
14 changes: 12 additions & 2 deletions src/ios/CodePushReportingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ + (void)reportStatus:(StatusReport*)statusReport withWebView:(UIView*)webView {

/* JS function to call: window.codePush.reportStatus(status: number, label: String, appVersion: String, deploymentKey: String) */
NSString* script = [NSString stringWithFormat:@"document.addEventListener(\"deviceready\", function () { window.codePush.reportStatus(%i, %@, %@, %@, %@, %@); });", (int)statusReport.status, labelParameter, appVersionParameter, deploymentKeyParameter, lastVersionLabelOrAppVersionParameter, lastVersionDeploymentKeyParameter];
#if WK_WEB_VIEW_ONLY
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
// The WKWebView requires JS evaluation to occur on the main
// thread starting with iOS11, so ensure that we dispatch to it before executing.
dispatch_async(dispatch_get_main_queue(), ^{
[webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:script withObject: NULL];
});
}
#else
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
// The WKWebView requires JS evaluation to occur on the main
// thread starting with iOS11, so ensure that we dispatch to it before executing.
Expand All @@ -47,6 +56,7 @@ + (void)reportStatus:(StatusReport*)statusReport withWebView:(UIView*)webView {
[(UIWebView*)webView stringByEvaluatingJavaScriptFromString:script];
});
}
#endif
}
}

Expand All @@ -62,7 +72,7 @@ + (BOOL)hasFailedReport {
if (HasFailedReport == -1) {
HasFailedReport = [self getFailedReport] != nil;
}

return HasFailedReport;
}

Expand All @@ -72,7 +82,7 @@ + (StatusReport*)getFailedReport {
if (!failedReportDict) {
return nil;
}

return [[StatusReport alloc] initWithDictionary:failedReportDict];
}

Expand Down

0 comments on commit 9e90116

Please sign in to comment.