Skip to content

Commit be605b9

Browse files
funnel20futuretap
authored andcommitted
Added WKWebView configuration and set other properties
See: #515
1 parent 2b6fbe4 commit be605b9

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

Sources/InAppSettingsKit/Controllers/IASKAppSettingsWebViewController.m

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ - (void)loadView {
8686
self.progressView.progress = 0.0;
8787
self.progressView.hidden = YES; // Will be shown by observer when enabled
8888
self.progressView.translatesAutoresizingMaskIntoConstraints = NO; // Disable autoresizing mask for layout constraints
89-
89+
9090
// Create UIBarButtonItems with SF Symbols:
9191
if (@available(iOS 13.0, *)) {
9292
self.backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"chevron.backward"]
@@ -147,10 +147,34 @@ - (void)loadView {
147147
- (void)viewDidLoad {
148148
[super viewDidLoad];
149149

150-
// Initialize the webView
151-
self.webView = [[WKWebView alloc] init];
152-
self.webView.translatesAutoresizingMaskIntoConstraints = NO; // Disable autoresizing mask for layout constraints
150+
// Create a configuration for the webView, which sets the subset of properties that Interface Builder in Xcode (version 15.4) shows when adding a WKWebView. The Xcode titles are put in the comments:
151+
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
152+
configuration.suppressesIncrementalRendering = NO; // Display: Incremental Rendering
153+
configuration.allowsAirPlayForMediaPlayback = YES; // Media: AirPlay
154+
configuration.allowsInlineMediaPlayback = YES; // Media: Inline Playback
155+
configuration.allowsPictureInPictureMediaPlayback = YES; // Media: Picture-in-Picture
156+
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll; // Interaction: For Audio/Video Playback -> Disable automatic start explicitely, since the video will be presented fullscreen after page load.
157+
configuration.dataDetectorTypes = WKDataDetectorTypeAll; // Data Detectors: All
158+
if (@available(iOS 14.0, *)) {
159+
configuration.defaultWebpagePreferences.allowsContentJavaScript = YES; // JavaScript: Enabled
160+
}
161+
else {
162+
configuration.preferences.javaScriptEnabled = YES; // Deprecated since iOS 14.0
163+
}
164+
configuration.preferences.javaScriptCanOpenWindowsAutomatically = NO; // JavaScript: Can Auto-open Windows -> Disable explicitely for security reasons.
165+
166+
// Initialize the webView with the configuration in an empty frame (size will be updated in `-viewWillLayoutSubviews` after constraints have been added):
167+
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
168+
self.webView.translatesAutoresizingMaskIntoConstraints = NO; // Disable autoresizing mask for layout constraints
153169
self.webView.navigationDelegate = self;
170+
171+
// Set other Xcode Interface Builder properties directly on webView:
172+
self.webView.allowsBackForwardNavigationGestures = YES; // Interaction: Back/Forward Gestures
173+
if (@available(iOS 16.0, *)) {
174+
self.webView.findInteractionEnabled = YES; // Interaction: Find & Replace
175+
}
176+
self.webView.allowsLinkPreview = YES; // Display: Link Preview
177+
154178
[self.view addSubview:self.webView];
155179

156180
// Create constraints to match the entire safe area layout:
@@ -185,6 +209,12 @@ - (void)viewDidLoad {
185209
}
186210
}
187211

212+
- (void)viewWillLayoutSubviews {
213+
[super viewWillLayoutSubviews];
214+
215+
self.webView.frame = self.view.bounds;
216+
}
217+
188218
- (void)viewWillAppear:(BOOL)animated {
189219
[super viewWillAppear:animated];
190220

0 commit comments

Comments
 (0)