What HTTP User-Agent does my iOS program advertise itself as?

18,039

Solution 1

Your original assumption is partly incorrect- A custom User-agent string is used for NSURLRequests from your app. In my testing, the string is

<product-name>/<build-number> CFNetwork/548.0.3 Darwin/11.2.0

However, some requests from UIWebView use this user-agent string

Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A334

presumably so that websites can optimise their HTML for the device even if it's not MobileSafari.

Solution 2

Looking at this related question ( Changing the userAgent of NSURLConnection ), it looks like it is pretty easy to make a user-agent change for NSURLConnection.

As for the other classes (UIWebView, AVPlayer, MPMoviePlayerViewController), there's no easy way to mess with the underlying NSURLConnections.

If you really want to change the user-agent for all HTTP requests, I'd suggest looking into Objective-C Class Posing to replace NSURLConnection (which hopefully wouldn't require completely reimplementing it).

Share:
18,039

Related videos on Youtube

Donald Burr
Author by

Donald Burr

Software engineer by day; computer enthusiast, anime fanatic, amateur podcaster, and sci-fi nut by night.

Updated on June 04, 2022

Comments

  • Donald Burr
    Donald Burr almost 2 years

    I've written an app for my podcast, Otaku no Podcast. In various parts of the app, I use NSURLConnection (fetch RSS feeds), UIWebView (display website content), AVPlayer (play MP3 audio files off our CDN), and MPMoviePlayerViewController (play video files off our CDN). Now, since all of these make HTTP requests of some sort, I'm assuming that they will advertise themselves with the standard iPhone User-agent string. (if my assumption is incorrect please let me know) This means that, based on reading my log files, I have no way of telling which of my visitors is coming in via plain old mobile Safari, vs. using my app.

    Is there a way of changing the User-Agent to one of my own? I found this question on SO that describes how to do this with NSURL but I can't find any information about any of the above classes that I am using.