@@ -195,7 +195,14 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti
195195 [configuration setValue: [NSNumber numberWithBool: YES ]
196196 forKey: _BGStatus];
197197 }
198-
198+ NSString *userAgent = configuration.applicationNameForUserAgent ;
199+ if (
200+ [settings cordovaSettingForKey: @" OverrideUserAgent" ] == nil &&
201+ [settings cordovaSettingForKey: @" AppendUserAgent" ] != nil
202+ ) {
203+ userAgent = [NSString stringWithFormat: @" %@ %@ " , userAgent, [settings cordovaSettingForKey: @" AppendUserAgent" ]];
204+ }
205+ configuration.applicationNameForUserAgent = userAgent;
199206 configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey: @" AllowInlineMediaPlayback" defaultValue: YES ];
200207 configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey: @" SuppressesIncrementalRendering" defaultValue: NO ];
201208 configuration.allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey: @" MediaPlaybackAllowsAirPlay" defaultValue: YES ];
@@ -270,8 +277,9 @@ - (void)pluginInitialize
270277 // add to keyWindow to ensure it is 'active'
271278 [UIApplication.sharedApplication.keyWindow addSubview: self .engineWebView];
272279
273- if ([self .viewController isKindOfClass: [CDVViewController class ]]) {
274- wkWebView.customUserAgent = ((CDVViewController*) self.viewController ).userAgent ;
280+ NSString * overrideUserAgent = [settings cordovaSettingForKey: @" OverrideUserAgent" ];
281+ if (overrideUserAgent != nil ) {
282+ wkWebView.customUserAgent = overrideUserAgent;
275283 }
276284
277285 if ([self .viewController conformsToProtocol: @protocol (WKUIDelegate)]) {
@@ -670,9 +678,6 @@ - (void)webView:(WKWebView*)webView didStartProvisionalNavigation:(WKNavigation*
670678
671679- (void )webView : (WKWebView *)webView didFinishNavigation : (WKNavigation *)navigation
672680{
673- CDVViewController* vc = (CDVViewController*)self.viewController ;
674- [CDVUserAgentUtil releaseLock: vc.userAgentLockToken];
675-
676681 [[NSNotificationCenter defaultCenter ] postNotification: [NSNotification notificationWithName: CDVPageDidLoadNotification object: webView]];
677682}
678683
@@ -684,7 +689,6 @@ - (void)webView:(WKWebView*)theWebView didFailProvisionalNavigation:(WKNavigatio
684689- (void )webView : (WKWebView *)theWebView didFailNavigation : (WKNavigation *)navigation withError : (NSError *)error
685690{
686691 CDVViewController* vc = (CDVViewController*)self.viewController ;
687- [CDVUserAgentUtil releaseLock: vc.userAgentLockToken];
688692
689693 NSString * message = [NSString stringWithFormat: @" Failed to load webpage with error: %@ " , [error localizedDescription ]];
690694 NSLog (@" %@ " , message);
0 commit comments