I have a business need to be able to customize the UserAgent for an embedded UIWebView. (For instance, I\'d like the server to respond differently if, say, a user is using
By pooling the answer by Louis St-Amour and the NSUserDefaults+UnRegisterDefaults
category from this question/answer, you can use the following methods to start and stop user-agent spoofing at any time while your app is running:
#define kUserAgentKey @"UserAgent"
- (void)startSpoofingUserAgent:(NSString *)userAgent {
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ kUserAgentKey : userAgent }];
}
- (void)stopSpoofingUserAgent {
[[NSUserDefaults standardUserDefaults] unregisterDefaultForKey:kUserAgentKey];
}