Change User Agent in iOS

Sometimes, different User Agents will show different content in the WebView.
in order to cater your html content, you will need to change UIWebView’s user agent.

Add the below code in AppDelegate.m

 + (void)initialize {

// Set user agent (the only problem is that we can’t modify the User-Agent later in the program)

NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:@”Your User Agent”, @”UserAgent”, nil];

[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];

}

Don’t forget to fill in “Your User Agent”.
For example, my user agent is

Mozilla/5.0 (iPad; CPU OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53

Find your own user agent from WhatsMyUserAgent

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s