When attempting to get the headers from an HttpUrlResponse, I am finding the iOS simulator is case-insensitive and a real device is case-sensitive.
The web service returns an HTTP header "Grandmas-Cookies: XXXX"
When the header key has uppercase letters:
urlResponse.response.allHeaderFields["Grandmas-Cookies"] as? String
- The simulator does NOT find the key.
- A real device sees the key.
When the header key has all lowercase letters:
urlResponse.response.allHeaderFields["grandmas-cookies"] as? String
- The simulator does find the key.
- A real device does NOT see the key.
Is there a setting I can make to the simulator to behave similarly to the real device? Changing the HTTP headers in the web service to lowercase is not desirable at this point but it is strange this started occurring only recently (yeah it's one of those fun times).
Edit:
@Adam I found a better way to ensure that this isn't an issue.
I created this function that makes the check case insensitive.
The below may still be useful for some people.
To solve this issue I created a
struct
. Inside thestruct
I created a static variablegrandmasCookies
that can now be referenced from anywhere within your app. This returns the upper casewhen you are running on a phone device.
This returns lowercase
when you are running in a simulator on a device such as a MacBook Pro.
I created a second convenience variable
isSimulator
which returns true when running from a simulator and false when running on a phone device.I adapted code from this StackOverflow post to make a solution that works for your scenario and one that I faced as well.