Reputation: 308
So it looks like the default usage of NSURLConnection has a UserAgent that does not match that of Safari on the same device. So the question is: How do I change NSURLConnection to use what is the default UserAgent of Safari?
I found a few posts on SO that talk about how to set the UA to something unique and that is not what I am looking to do. I just want to put the UA back to what it really should be.
Note: Since iOS updates on a regular basis, I need something that will work on iOS7 as well have some sort of backwards compatibility.
Thanks!
Upvotes: 0
Views: 738
Reputation: 3034
I believe the user-agent by default on an NSURLConnection uses your app name and version. I don’t know of any magical way to set it to automatically use the current mobile Safari user agent string. The only thing I would possibly suggest is to try and use http://whatsmyuseragent.com from Safari on the device, then based on the results, hardcode the user agent string in the request to mimic it:
[request addValue:myHardcodedUserAgent forHTTPHeaderField:@"User-Agent”];
Of course, as Safari's user agent string changes, your's will not.
Upvotes: 1