6

I want to programmatically retrieve my application’s User-Agent string. (Note: not the UA of a UIWebView in my application; the UA for NSURLConnection-based HTTP requests.)

There’s lots of guides on how to read an application's UIWebView User-Agent, but none on how to get at the <appname>/1.0 CFNetwork/456.23 string that CFNetwork stuffs inside its HTTP requests. There’s API for CFHTTPMessage to copy out all header fields, but I only have an NSURLRequest and an NSURLResponse, and these are unbridged opaque types. Help!

(Some good background reading: Changing the userAgent of NSURLConnection mentions the format that I want to get at. What HTTP User-Agent does my iOS program advertise itself as? does as well.)

Community
  • 1
  • 1
cbowns
  • 6,295
  • 5
  • 47
  • 64
  • Instead of retrieving the header, could you just derive it from info in the bundle, UIDevice, and a table like the following? Of course, you'd need to complete the table, but there are a finite number of device/os combos that your app would care about... http://stackoverflow.com/questions/6239553/a-list-of-linking-cfnetwork-version-numbers-to-the-version-of-ios – sam Apr 27 '12 at 20:33

1 Answers1

2

Completely twisted: create a local socket on port 80 and make a local request (to yourself), read the HTTP headers.

Cody Caughlan
  • 32,456
  • 5
  • 63
  • 68
  • 1
    This is, no joke, one of the better solutions I’ve come up with thus far. This is just insane, right? – cbowns Apr 26 '12 at 23:32