-1

using IBM MobileFirst Platform 7.0 I am unable to modify the user agent of a UIWebView. I have a hybrid application (HTML/CSS, JS, Objective-C) and tried UIWebView iOS5 changing user-agent (both question and answer version):

@implementation MyAppDelegate

+ (void)initialize
{
    NSString* useragent = @"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0";
    NSLog(@"Setting User-Agent to: %@", useragent);
    NSDictionary* dictionary = [NSDictionary dictionaryWithObjectsAndKeys:useragent, @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

}   
(...)

and/or

 (...)
 [request setValue:@"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0" forHTTPHeaderField:@"User-Agent"];                   
 [webView loadRequest: request];
 NSLog(@"Getting UA: %@", [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]);
 (...)

but my output is:

 Getting UA: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20130401 Firefox/31.0/Worklight/7.0.0.0

I tried to find this token somewhere in the configurations, but was unsuccessful...

I was able to reproduce this by adding the above code to the IBM Example, project "IncludeExternalPages". I'll be happy to provide the code if this helps.

Community
  • 1
  • 1
Qais
  • 1
  • 1
  • 2

2 Answers2

0

This may be technically possible but note that MobileFirst Platform's framework relies on the default useragent provided by it and so it is not advised that you will change it.

You should ask yourself:

  • Why do I need to change it
  • Can I handle it differently (headers? by code?)
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • HI Idan, thank you for the quick reply. The main issue is that I need to access/integrate a proprietary web interface, which does not provide inherent support for MacOS/iOS etc. We have triggered to investigate this further from a provider side, but this obviously is a more longer process than testing whether simply changing the UA does simply avoid these issues (Google Chrome for iOS works fine, while Safari does not, aso). tl;dr: I need this for testing in our development. Regardless, not being able to set the UA seems strange to me. Thanks. – Qais Jun 30 '15 at 10:26
0

Ok, the only thing that worked for me was to use:

i)

NSString* useragent = @"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0";
NSLog(@"Setting User-Agent to: %@", useragent);
NSDictionary* dictionary = [NSDictionary dictionaryWithObjectsAndKeys:useragent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

ii) in the beginning of wlInitDidCompleteSuccessfully within the AppDelegate

iii) after uninstalling and reinstalling the app

Qais
  • 1
  • 1
  • 2