get CFNetwork Version number

Is there any way to get CFNetwork version number?

What do you need that value for?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

em... it is hard to explatin.

Put simply, we want do make a User-Agent content exactly same with iOS system.

If we can get CFNetwork version ,we can combine it.

If not, we can only send a request and get it from the server and send it back to APP.

we want do make a

User-Agent
content exactly same with iOS system. If we can get CFNetwork version, we can combine it.

The problem with this approach is that the default

User-Agent
string has a complex structure, where the CFNetwork version is just one component of that structure, and there’s no guarantee that this structure will be the same from release to release of the system. So once you get the CFNetwork version string, there’s no supported way to build the default
User-Agent
string from that.

Indeed, while digging into this today I noticed that iOS and macOS have different default user agent strings!

Regardless of what else you do here, my recommendation is that you file an enhancement request for an API to get this string, making sure to include a detailed justification as to why you need it. Please post your bug number, just for the record.

If not, we can only send a request and get it from the server and send it back to APP.

Honestly, this seems like a better approach to me.

Notwithstanding the above, you can get the CFNetwork version from its bundle with the code shown below:

func cfNetworkVersion() -> String? {
    guard
        let bundle = Bundle(identifier: "com.apple.CFNetwork"),
        let versionAny = bundle.infoDictionary?[kCFBundleVersionKey as String],
        let version = versionAny as? String
    else { return nil }
    return version
}

Make sure to handle a

nil
result here; there’s a bunch of ways that this code could break in the future.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you very much for your help. For now, we know NSURLSession send a request with empty User-Agent, will auto add a defult User-agent like :

(app name)/1.0.4.14 CFNetwork/758.3.15 Darwin/15.6.0

and we already know Darwin version can get from API. and if the app name contains no ASIC code, it will be URI encode. So If we can get CFNetwork version, I think we can create same User-Agent as iOS system in most situations.


And why we want's to create User-agent:

We are using NSURLProtocol to get user request and make it to cross our proxy server, and we don't want to change anything of user's request, but when user's request come to protocol we can't get the user-agent in the reqeust header, so i think we need to create it by ourself.

If not, we can only send a request and get it from the server and send it back to APP.

Honestly, this seems like a better approach to me.

This way is a little complex to us, and it also need more time than just create the User-Agent, since our proxy service need start the faster the better。



Regardless of what else you do here, my recommendation is that you file an enhancement request for an API to get this string, making sure to include a detailed justification as to why you need it. Please post your bug number, just for the record.


Feedback num: FB7380014

I think we can create same User-Agent as iOS system in most situations.

Until your code moves to a different platform, like the Mac. Or Apple changes how it calculates the default user agent string, which we’ve done many times in the past and it wouldn’t surprise me if we did in the future. Doing this is inherently brittle.

Then again…

We are using

NSURLProtocol

This is also massively brittle. Are you doing this in order to intercept the requests issued by a

UIWebView
?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Our SDK is only support iOS.

> This is also massively brittle. Are you doing this in order to intercept the requests issued by a

UIWebView
?

No only UIWebView, NURLSession, URLConnection as well, but since we can get user-agent in protocol when it's a uiwebview request, so we don`t need to create it ourself.

No only

UIWebView
,
NURLSession
,
URLConnection

OK, let’s break this down:

  • You shouldn’t be using

    NSURLConnection
    any more.
  • For

    NSURLSession
    , you can apply custom proxy settings using the
    connectionProxyDictionary
    property. There’s no need for an
    NSURLProtocol
    subclass in that case.
  • That just leaves

    UIWebView
    , right?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Maybe you don't know my situation, I dev http proxy server SDK, so using which tool to send the request is decide by our customer.

And I required a Technical Support No. 71730485 recentily, and you help me a lot 😉, can you remember ?

And I required a Technical Support No. 71730485 recentily, and you help me a lot, can you remember?

Ah, yes, that one. Unfortunately DevForums deliberately masks real names, so it’s hard for me to match up DevForums threads against DTS tech support incidents.

I dev http proxy server SDK, so using which tool to send the request is decide by our customer.

On the plus side, such a product is going to be sufficiently brittle that the brittleness of your CFNetwork version code is the least of your worries (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
get CFNetwork Version number
 
 
Q