Setting User-Agent in AFNetworking

Mbeezy picture Mbeezy · Apr 6, 2015 · Viewed 7.4k times · Source

our iOS app recently got rejected by Apple because it was not able to establish a valid connection to our server api. We are using a specially formatted user-agent to register the device token and so on. If the user-agent does not fit into our sheme, the api blocks the request.

It all worked pretty well testing the app on the simulator as well as on a real device. The user-agent was set correctly and the api calls worked.

As Apple tested the app, they rejected it because the app was unable to connect to the api. As we checked the server logfiles, we noticed, that every request sent out by the Apple testers had a completely different user-agent, than the one we set in the code.

The (correct) user-agent, that was set as we tested the app:

AppName-App/010002 iOS/8.1.2 on Apple iPhone/DeviceToken

The (incorrect) user-agent, as it appeared in our logs:

AppName/1.0.0.2 (iPad; iOS 8.1.3; Scale/2.00)

The app uses AFNetworking and sets its user-agent as follows:

ConnectionManager.requestSerializer.setValue(IOSREQUESTHEADER, forHTTPHeaderField: "user-agent")

Do you have any idea why this is not working as Apple tests the app, while its completely okay when we do?

Best regards

Answer

nail picture nail · Jun 10, 2015

I tried to change my user agent with code below

[self.requestSerializer setValue:@"VAL" forHTTPHeaderField:@"user-agent"];

but has no effect until rename @"user-agent" to @"User-Agent"