From 4ef6106259bb2cf983cdc83b30d11c806c8e0fec Mon Sep 17 00:00:00 2001 From: Connor Pearson Date: Fri, 13 Mar 2015 13:52:30 -0400 Subject: [PATCH] CB-3360: Set custom inappbrowser user agent for ios This closes #94 Signed-off-by: Shazron Abdullah --- src/ios/CDVInAppBrowser.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index 7cffac3..6ccdd50 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -47,6 +47,11 @@ _callbackIdPattern = nil; } +- (id)settingForKey:(NSString*)key +{ + return [self.commandDelegate.settings objectForKey:[key lowercaseString]]; +} + - (void)onReset { [self close:nil]; @@ -137,8 +142,16 @@ } if (self.inAppBrowserViewController == nil) { - NSString* originalUA = [CDVUserAgentUtil originalUserAgent]; - self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:originalUA prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions]; + NSString* userAgent = [CDVUserAgentUtil originalUserAgent]; + NSString* overrideUserAgent = [self settingForKey:@"OverrideUserAgent"]; + NSString* appendUserAgent = [self settingForKey:@"AppendUserAgent"]; + if(overrideUserAgent){ + userAgent = overrideUserAgent; + } + if(appendUserAgent){ + userAgent = [userAgent stringByAppendingString: appendUserAgent]; + } + self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:userAgent prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions]; self.inAppBrowserViewController.navigationDelegate = self; if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {