Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change User-Agent and remove App Name and defaults iOS

I am trying to change the User-Agent in iOS, however when I add my custom User-Agent it appends it to the existing User-Agent that contains my app name.

This is the code I am using:

NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:endpoint parameters:nil];
    [request addValue:@"MyUserAgent (iPhone; iOS 7.0.2; gzip)" forHTTPHeaderField:@"User-Agent"];

And the User-Agent appears like this:

MyAppName/1.0 (iPhone; iOS 7.0.2; Scale/2.00),MyUserAgent (iPhone; iOS 7.0.2; gzip)

I've read that this might not be possible as the App name is automatically added to the User-Agent, however I have seen another similar app to mine that has managed to customise the User-Agent completely.

like image 216
Darren Avatar asked Oct 10 '13 13:10

Darren


People also ask

How do I remove user agent from my iPhone?

It's not possible to change your user agent string on iPhone. The user agent string you provided is the standard string that an iPhone uses; nothing out of the ordinary there.

What is AppleWebKit 537.36 Khtml like Gecko used for?

AppleWebKit/537.36 indicates what browser rendering engine is used. A rendering engine is what transforms HTML into an interactive webpage on the user's screen. The WebKit browser engine was developed by Apple and is primarily used by Safari, Chromium, and all other WebKit-based browsers. (KHTML, like Gecko).


1 Answers

To override the default user agent, use setValue:forHTTPHeaderField: instead of addValue:forHTTPHeaderField:. For example:

[request setValue:@"MyUserAgent (iPhone; iOS 7.0.2; gzip)" forHTTPHeaderField:@"User-Agent"];
like image 60
neilco Avatar answered Sep 29 '22 17:09

neilco