User-Agent not changing in NSMutableURLRequest

心不动则不痛 提交于 2019-12-06 01:55:59

I "solved" my problem by putting in the didFinishLaunchingWithOptions of my AppDelegate.m the following code:

 NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:@"YOUR CUSTOM USER-AGENT", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];

The thing is that i cannot append the text to the user agent itself, but i can write the data i need to differentiate between the access to the web page from the different apps or web browsers.

Thank you all for your help.

It won't work like that. UIWebView overrides the User-Agent field.

If you try to log the User-Agent in the webView:shouldStartLoadWithRequest:navigationType: method, you'll see that it's already overridden, however you can use NSURLConnection to load your request with a custom User-Agent and then use the loadHTMLString:baseURL: method or loadData:MIMEType:textEncodingName:baseURL: method from UIWebView to display the downloaded data from NSURLConnection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!