Skip to content

Commit 82bbe29

Browse files
Maik HummelNiklasMerz
authored andcommitted
(ios) add compile-time decision for disabling UIWebView (#584)
1 parent 785fc4c commit 82bbe29

File tree

3 files changed

+91
-47
lines changed

3 files changed

+91
-47
lines changed

src/ios/CDVInAppBrowser.m

Lines changed: 84 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Licensed to the Apache Software Foundation (ASF) under one
1919

2020
#import "CDVInAppBrowser.h"
2121
#import "CDVInAppBrowserOptions.h"
22+
#if !WK_WEB_VIEW_ONLY
2223
#import "CDVUIInAppBrowser.h"
24+
#endif
2325
#import "CDVWKInAppBrowser.h"
2426
#import <Cordova/CDVPluginResult.h>
2527

@@ -49,86 +51,122 @@ - (void)open:(CDVInvokedUrlCommand*)command
4951
return;
5052
}
5153
self.usewkwebview = browserOptions.usewkwebview;
52-
if(self.usewkwebview){
53-
[[CDVWKInAppBrowser getInstance] open:command];
54-
}else{
55-
[[CDVUIInAppBrowser getInstance] open:command];
56-
}
54+
#if WK_WEB_VIEW_ONLY
55+
[[CDVWKInAppBrowser getInstance] open:command];
56+
#else
57+
if(self.usewkwebview){
58+
[[CDVWKInAppBrowser getInstance] open:command];
59+
}else{
60+
[[CDVUIInAppBrowser getInstance] open:command];
61+
}
62+
#endif
5763
}
5864

5965
- (void)close:(CDVInvokedUrlCommand*)command
6066
{
61-
if(self.usewkwebview){
62-
[[CDVWKInAppBrowser getInstance] close:command];
63-
}else{
64-
[[CDVUIInAppBrowser getInstance] close:command];
65-
}
67+
#if WK_WEB_VIEW_ONLY
68+
[[CDVWKInAppBrowser getInstance] close:command];
69+
#else
70+
if(self.usewkwebview){
71+
[[CDVWKInAppBrowser getInstance] close:command];
72+
}else{
73+
[[CDVUIInAppBrowser getInstance] close:command];
74+
}
75+
#endif
6676
}
6777

6878

6979
- (void)show:(CDVInvokedUrlCommand*)command
7080
{
71-
if(self.usewkwebview){
72-
[[CDVWKInAppBrowser getInstance] show:command];
73-
}else{
74-
[[CDVUIInAppBrowser getInstance] show:command];
75-
}
81+
#if WK_WEB_VIEW_ONLY
82+
[[CDVWKInAppBrowser getInstance] show:command];
83+
#else
84+
if(self.usewkwebview){
85+
[[CDVWKInAppBrowser getInstance] show:command];
86+
}else{
87+
[[CDVUIInAppBrowser getInstance] show:command];
88+
}
89+
#endif
7690
}
7791

7892
- (void)hide:(CDVInvokedUrlCommand*)command
7993
{
80-
if(self.usewkwebview){
81-
[[CDVWKInAppBrowser getInstance] hide:command];
82-
}else{
83-
[[CDVUIInAppBrowser getInstance] hide:command];
84-
}
94+
#if WK_WEB_VIEW_ONLY
95+
[[CDVWKInAppBrowser getInstance] hide:command];
96+
#else
97+
if(self.usewkwebview){
98+
[[CDVWKInAppBrowser getInstance] hide:command];
99+
}else{
100+
[[CDVUIInAppBrowser getInstance] hide:command];
101+
}
102+
#endif
85103
}
86104

87105

88106
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command
89107
{
90-
if(self.usewkwebview){
91-
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
92-
}else{
93-
[[CDVUIInAppBrowser getInstance] injectScriptCode:command];
94-
}
108+
#if WK_WEB_VIEW_ONLY
109+
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
110+
#else
111+
if(self.usewkwebview){
112+
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
113+
}else{
114+
[[CDVUIInAppBrowser getInstance] injectScriptCode:command];
115+
}
116+
#endif
95117
}
96118

97119
- (void)injectScriptFile:(CDVInvokedUrlCommand*)command
98120
{
99-
if(self.usewkwebview){
100-
[[CDVWKInAppBrowser getInstance] injectScriptFile:command];
101-
}else{
102-
[[CDVUIInAppBrowser getInstance] injectScriptFile:command];
103-
}
121+
#if WK_WEB_VIEW_ONLY
122+
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
123+
#else
124+
if(self.usewkwebview){
125+
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
126+
}else{
127+
[[CDVUIInAppBrowser getInstance] injectScriptCode:command];
128+
}
129+
#endif
104130
}
105131

106132
- (void)injectStyleCode:(CDVInvokedUrlCommand*)command
107133
{
108-
if(self.usewkwebview){
109-
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
110-
}else{
111-
[[CDVUIInAppBrowser getInstance] injectStyleCode:command];
112-
}
134+
#if WK_WEB_VIEW_ONLY
135+
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
136+
#else
137+
if(self.usewkwebview){
138+
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
139+
}else{
140+
[[CDVUIInAppBrowser getInstance] injectStyleCode:command];
141+
}
142+
#endif
113143
}
114144

115145
- (void)injectStyleFile:(CDVInvokedUrlCommand*)command
116146
{
117-
if(self.usewkwebview){
118-
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
119-
}else{
120-
[[CDVUIInAppBrowser getInstance] injectStyleFile:command];
121-
}
147+
#if WK_WEB_VIEW_ONLY
148+
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
149+
#else
150+
if(self.usewkwebview){
151+
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
152+
}else{
153+
[[CDVUIInAppBrowser getInstance] injectStyleFile:command];
154+
}
155+
#endif
122156
}
123157

124158
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
125159
{
126-
if(self.usewkwebview){
127-
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
128-
}else{
129-
[[CDVUIInAppBrowser getInstance] loadAfterBeforeload:command];
130-
}
160+
#if WK_WEB_VIEW_ONLY
161+
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
162+
#else
163+
if(self.usewkwebview){
164+
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
165+
}else{
166+
[[CDVUIInAppBrowser getInstance] loadAfterBeforeload:command];
167+
}
168+
#endif
131169
}
132170

133171

134-
@end
172+
@end

src/ios/CDVUIInAppBrowser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
under the License.
1818
*/
1919

20+
#if !WK_WEB_VIEW_ONLY
21+
2022
#import <Cordova/CDVPlugin.h>
2123
#import <Cordova/CDVInvokedUrlCommand.h>
2224
#import <Cordova/CDVScreenOrientationDelegate.h>
@@ -89,3 +91,5 @@
8991
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
9092

9193
@end
94+
95+
#endif

src/ios/CDVUIInAppBrowser.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Licensed to the Apache Software Foundation (ASF) under one
1717
under the License.
1818
*/
1919

20+
#if !WK_WEB_VIEW_ONLY
21+
2022
#import "CDVUIInAppBrowser.h"
2123
#import <Cordova/CDVPluginResult.h>
2224
#import <Cordova/CDVUserAgentUtil.h>
@@ -1126,4 +1128,4 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
11261128

11271129
@end
11281130

1129-
1131+
#endif

0 commit comments

Comments
 (0)