Willy
Willy

Reputation: 313

Modifying User-Agent string on Cordova / PhoneGap application for iOS

I am following the below GitHub pull request to see if this is going to be possible, there has been activity in the sense of a code change (17 lines) but I am not sure on how to implement this into my iOS application... Does anyone have any ideas here? (cordova 5.1)

https://github.com/apache/cordova-plu...

Cheers, Will

Upvotes: 2

Views: 3358

Answers (2)

Brijmohan Karadia
Brijmohan Karadia

Reputation: 447

Android: add below code in config.xml

<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />

Upvotes: 2

tabrindle
tabrindle

Reputation: 1874

It seems that your link is broken, but I think I know what you are asking for. This is actually a relatively new feature for Cordova, coming from this issue.

It was launched in cordova-ios 3.9.0, about a month ago. See these release notes. (Keep in mind that the platform versions like cordova-ios and cordova-android are different than the version number you gave 5.1, which is the CLI version)

You can set a preference in your config.xml file, in the root of your project.

<preference name="AppendUserAgent" value="myapp" />

Will yield something like this:

"Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.114 Mobile Safari/537.36 myapp"

While this:

<preference name="OverrideUserAgent" value="Better_be_really_specific_here" />

Will only give you this:

"Better_be_really_specific_here" 

I recommend only using the AppendUserAgent, as if you just use override, you will lose all the rest of the valuable information like device, OS, browser version etc that you can get from the UA.

Upvotes: 6

Related Questions