From b60959ac31106a404774f641e063096014269188 Mon Sep 17 00:00:00 2001 From: Ortwin Gentz Date: Mon, 11 Nov 2024 22:35:23 +0100 Subject: [PATCH] Make webViewConfiguration overridable --- InAppSettingsKit.podspec | 2 +- .../IASKAppSettingsWebViewController.m | 36 ++++++++++--------- .../IASKAppSettingsWebViewController.h | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/InAppSettingsKit.podspec b/InAppSettingsKit.podspec index 95377dd5..f77b5883 100644 --- a/InAppSettingsKit.podspec +++ b/InAppSettingsKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'InAppSettingsKit' - s.version = '3.8.4' + s.version = '3.8.5' s.summary = 'This iPhone framework allows settings to be in-app in addition to being in the Settings app.' s.description = <<-DESC diff --git a/Sources/InAppSettingsKit/Controllers/IASKAppSettingsWebViewController.m b/Sources/InAppSettingsKit/Controllers/IASKAppSettingsWebViewController.m index e8c1f944..10cec52a 100644 --- a/Sources/InAppSettingsKit/Controllers/IASKAppSettingsWebViewController.m +++ b/Sources/InAppSettingsKit/Controllers/IASKAppSettingsWebViewController.m @@ -55,6 +55,25 @@ - (id)initWithFile:(NSString*)urlString specifier:(IASKSpecifier*)specifier { return self; } +- (WKWebViewConfiguration*)webViewConfiguration { + // 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: + WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; + configuration.suppressesIncrementalRendering = NO; // Display: Incremental Rendering + configuration.allowsAirPlayForMediaPlayback = YES; // Media: AirPlay + configuration.allowsInlineMediaPlayback = YES; // Media: Inline Playback + configuration.allowsPictureInPictureMediaPlayback = YES; // Media: Picture-in-Picture + configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll; // Interaction: For Audio/Video Playback -> Disable automatic start explicitely, since the video will be presented fullscreen after page load. + configuration.dataDetectorTypes = WKDataDetectorTypeAll; // Data Detectors: All + if (@available(iOS 14.0, *)) { + configuration.defaultWebpagePreferences.allowsContentJavaScript = YES; // JavaScript: Enabled + } + else { + configuration.preferences.javaScriptEnabled = YES; // Deprecated since iOS 14.0 + } + configuration.preferences.javaScriptCanOpenWindowsAutomatically = NO; // JavaScript: Can Auto-open Windows -> Disable explicitely for security reasons. + return configuration; +} + - (void)loadView { // Set up the main view self.view = [[UIView alloc] init]; @@ -147,24 +166,9 @@ - (void)loadView { - (void)viewDidLoad { [super viewDidLoad]; - // 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: - WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; - configuration.suppressesIncrementalRendering = NO; // Display: Incremental Rendering - configuration.allowsAirPlayForMediaPlayback = YES; // Media: AirPlay - configuration.allowsInlineMediaPlayback = YES; // Media: Inline Playback - configuration.allowsPictureInPictureMediaPlayback = YES; // Media: Picture-in-Picture - configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll; // Interaction: For Audio/Video Playback -> Disable automatic start explicitely, since the video will be presented fullscreen after page load. - configuration.dataDetectorTypes = WKDataDetectorTypeAll; // Data Detectors: All - if (@available(iOS 14.0, *)) { - configuration.defaultWebpagePreferences.allowsContentJavaScript = YES; // JavaScript: Enabled - } - else { - configuration.preferences.javaScriptEnabled = YES; // Deprecated since iOS 14.0 - } - configuration.preferences.javaScriptCanOpenWindowsAutomatically = NO; // JavaScript: Can Auto-open Windows -> Disable explicitely for security reasons. // Initialize the webView with the configuration in an empty frame (size will be updated in `-viewWillLayoutSubviews` after constraints have been added): - self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; + self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:self.webViewConfiguration]; self.webView.translatesAutoresizingMaskIntoConstraints = NO; // Disable autoresizing mask for layout constraints self.webView.navigationDelegate = self; diff --git a/Sources/InAppSettingsKit/include/IASKAppSettingsWebViewController.h b/Sources/InAppSettingsKit/include/IASKAppSettingsWebViewController.h index e72b3e76..27ac70a5 100644 --- a/Sources/InAppSettingsKit/include/IASKAppSettingsWebViewController.h +++ b/Sources/InAppSettingsKit/include/IASKAppSettingsWebViewController.h @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, strong, readonly) WKWebView *webView; @property (nonatomic, strong, readonly) NSURL *url; @property (nullable, nonatomic, strong) NSString *customTitle; +@property (nonnull, nonatomic, readonly) WKWebViewConfiguration *webViewConfiguration; @end