Skip to content

Commit

Permalink
Make webViewConfiguration overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
futuretap committed Nov 11, 2024
1 parent be605b9 commit b60959a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion InAppSettingsKit.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b60959a

Please sign in to comment.