-1

I have a PhoneGap 3.0 app that I have built on the IOS platform.

I have added the following two lines to the didFinishLaunchingWithOptions method of AppDelegate.m to attempt to spoof a particular user agent (after looking through numerous SO questions):

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"my custom user agent", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

When I run the app in the IOS simulator and inspect navigator.userAgent, I get the expected "my custom user agent" as the output.

When I do a remote phonegap build, run the app on my iPhone and inspect navigator.userAgent, I get the standard iPhone user agent, not my custom one.

Why am I getting different outputs from navigator.userAgent on the simulator and my device?

Related SO questions:

Change Phonegap User Agent

Detect between a mobile browser or a PhoneGap application

Community
  • 1
  • 1
Chris McKinnel
  • 14,694
  • 6
  • 64
  • 67

1 Answers1

1

Why am I getting different outputs from navigator.userAgent on the simulator and my device?

When we do a remote phonegap build, we're effectively zipping up the assets of the project and uploading them, so any changes we make to files outside the www directory of the project are ignored.

The phonegap build service is doing its own build and creating its own AppDelegate.m, without the changes to edit the user agent, which explains why we're not seeing the custom user agent on the device and we are seeing it on the simulator.

Chris McKinnel
  • 14,694
  • 6
  • 64
  • 67