TruckMovers / cordova-plugin-remote-injection

DEPRECATED: Cordova plugin to allow a remote site to interact with cordova's javascript APIs when loaded within a cordova app.
Apache License 2.0
91 stars 95 forks source link

`WKWebViewOnly` setting for removing UIWebView #47

Open davidgovea opened 4 years ago

davidgovea commented 4 years ago

I know that PRs won't be merged in this repo, but adding this here for visibility. See Issue #46

The most straightforward way to fix the UIWebView deprecation issue is to remove all the related code. Several forks have done this; see:

This PR takes the same approach as cordova-ios and cordova-plugin-inappbrowser, implementing conditional compilation based on the WKWebViewOnly config.xml setting. See Cordova article here for more information.

Adding <preference name="WKWebViewOnly" value="true" /> to the ios platform in config.xml will cause UIWebView code to be removed.

However.. maybe the "remove-all" approach is better? Why do we ever need UIWebView code around now? This change does represent fewer lines changed, so maybe that's something.


This change can also be pulled in using patch-package:

patches/cordova-plugin-remote-injection+0.5.2.patch

diff --git a/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjection.m b/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjection.m
index 9c11eb9..7a72cb2 100644
--- a/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjection.m
+++ b/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjection.m
@@ -81,6 +81,10 @@ - (void) pluginInitialize
     }

     id webView = [self findWebView];
+    #if WK_WEB_VIEW_ONLY
+        webViewDelegate = [[CDVRemoteInjectionWKWebViewDelegate alloc] init];
+        [webViewDelegate initializeDelegate:self];
+    #else
     if ([webView isKindOfClass:[UIWebView class]]) {
         NSLog(@"Found UIWebView");
         webViewDelegate = [[CDVRemoteInjectionUIWebViewDelegate alloc] init];
@@ -96,6 +100,7 @@ - (void) pluginInitialize
     } else {
         NSLog(@"Not a supported web view implementation");
     }
+    #endif
 }

 /*
diff --git a/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.h b/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.h
index b451824..3967ca9 100644
--- a/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.h
+++ b/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.h
@@ -1,3 +1,5 @@
+#if !WK_WEB_VIEW_ONLY
+
 #import "CDVRemoteInjection.h"
 #import "CDVRemoteInjectionWebViewBaseDelegate.h"

@@ -11,3 +13,5 @@
 @interface CDVRemoteInjectionUIWebViewNotificationDelegate : WrappedDelegateProxy <UIWebViewDelegate>
 @property (readwrite, weak) CDVRemoteInjectionUIWebViewDelegate *webViewDelegate;
 @end
+
+#endif
diff --git a/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.m b/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.m
index bb0251e..d1c0dd4 100644
--- a/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.m
+++ b/node_modules/cordova-plugin-remote-injection/src/ios/CDVRemoteInjectionUIWebViewDelegate.m
@@ -2,6 +2,8 @@
 //  CDVRemoteInjection.m
 //

+#if !WK_WEB_VIEW_ONLY
+
 #import <Foundation/Foundation.h>

 #import "CDVRemoteInjectionUIWebViewDelegate.h"
@@ -98,3 +100,5 @@ - (void) retryCurrentRequest
 }

 @end
+
+#endif
fnicollet commented 3 years ago

As a side note on @davidgovea PR, the forks can be used in Cordova, by replacing the plugin name in package.json with the URL of a fork:

github:RobertY9/cordova-plugin-remote-injection

I was able to pass certification with this setting

Thanks @davidgovea ! Fabien