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

Commit 9e90116

Browse files
authored
Add flag for UIWebView usage (#588)
* Add flag for UIWebView usage
1 parent 2b8feca commit 9e90116

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ With the CodePush plugin installed, configure your app to use it via the followi
116116

117117
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.
118118

119+
*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:*
120+
```xml
121+
<preference name="WKWebViewOnly" value="true" />
122+
```
123+
119124
## Plugin Usage
120125

121126
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:

src/ios/CodePush.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ - (void)loadURL:(NSURL*)url {
401401
// maintaining back-compat with Cordova iOS 3.9.0, we need to conditionally
402402
// use the WebViewEngine for performing navigations only if the host app
403403
// is running 4.0.0+, and fallback to directly using the WebView otherwise.
404-
#ifdef __CORDOVA_4_0_0
404+
#if (WK_WEB_VIEW_ONLY && defined(__CORDOVA_4_0_0)) || defined(__CORDOVA_4_0_0)
405405
[self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]];
406406
#else
407407
[(UIWebView*)self.webView loadRequest:[NSURLRequest requestWithURL:url]];

src/ios/CodePushReportingManager.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ + (void)reportStatus:(StatusReport*)statusReport withWebView:(UIView*)webView {
3434

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];
37+
#if WK_WEB_VIEW_ONLY
38+
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
39+
// The WKWebView requires JS evaluation to occur on the main
40+
// thread starting with iOS11, so ensure that we dispatch to it before executing.
41+
dispatch_async(dispatch_get_main_queue(), ^{
42+
[webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:script withObject: NULL];
43+
});
44+
}
45+
#else
3746
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
3847
// The WKWebView requires JS evaluation to occur on the main
3948
// thread starting with iOS11, so ensure that we dispatch to it before executing.
@@ -47,6 +56,7 @@ + (void)reportStatus:(StatusReport*)statusReport withWebView:(UIView*)webView {
4756
[(UIWebView*)webView stringByEvaluatingJavaScriptFromString:script];
4857
});
4958
}
59+
#endif
5060
}
5161
}
5262

@@ -62,7 +72,7 @@ + (BOOL)hasFailedReport {
6272
if (HasFailedReport == -1) {
6373
HasFailedReport = [self getFailedReport] != nil;
6474
}
65-
75+
6676
return HasFailedReport;
6777
}
6878

@@ -72,7 +82,7 @@ + (StatusReport*)getFailedReport {
7282
if (!failedReportDict) {
7383
return nil;
7484
}
75-
85+
7686
return [[StatusReport alloc] initWithDictionary:failedReportDict];
7787
}
7888

0 commit comments

Comments
 (0)