Reputation: 604
This is driving me crazy. I have two apps that are just UIWebViews, using XCode 4.5.2 and the iOS 6.0 SDK. I want to change the UserAgent of the web calls. I'm using this code in both:
NSString *secretagent = @"MyUserAgent";
NSDictionary *dictionary = [[NSDictionary alloc]
initWithObjectsAndKeys:secretAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
What's killing me is that it works in one and not in the other, based on my scanning of the web logs. The one that doesn't work is still getting the UserAgent key changed, based on my checking with objectsForKey:@"UserAgent". It's just that nothing actually changes on the web request.
Any ideas? It's 3:30 AM and I just can't figure this out...
Upvotes: 3
Views: 3377
Reputation: 604
figured it out. you can't alter the user agent after the webview has been initialized. i moved the code to viewDidLoad, before I initialize the webview, and it works.
Upvotes: 6