When we meet some person, we always want to introduce ourselves from the best side. We can describe ourselves by telling the name and a few interesting facts.
In the computer world, if we behave as a user - we also should introduce ourselves. One of the options is to use User-Agent.
User-Agent
The User-Agent request header is a character string that lets servers and network peers identify the application, operating system, vendor, and/or version of the requesting user agent. source.
Mobile application in every request must send his User-Agent in the header with build version and device information.
format:
I’m mostly working with iOS, so this tutorial is dedicated to this OS.
So, the components are:
Headers Key
AppName and version
Info about Device
CFNetwork version
Darwin Version
Headers Key
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored.
User-Agent:<Value>
The list of the header key can be found for example here
AppName and Version
This information available in the u’r Info.plist file.
U can use the approach described here with InfoPlist struct like below:
Result - u can access all information within a few lines of code:
Info about Device
In general, u should collect few components. A lot of solutions are available for this purpose.
This is a framework, that uses for accessing network services and handling changes in network configurations. Build on abstractions of network protocols to simplify tasks such as working with BSD sockets, administering HTTP and FTP servers, and managing Bonjour services. Read more.