I'm porting my Android app to iOS and I'm at the chat stage.
Each message has its own date, and my server API (in PHP) has a method that fetches all messages since a date (so I can send a request with my lastMessageDate
and get any new messages that are not on the device whenever needed)
My database is MySQL and the server's timezone is GMT+2. The DB saves all dates as GMT+2, and PHP sends them as string back to the client.
In Android, and in my REST client for testing, calling the following request gives the "No new messages" message, as it should:
In iOS, since the OS translates all Dates to UTC, before sending the date, I turn in into a GMT+2 string. I've been testing and debugging this date string, and it is indeed in GMT+2, as my server expects it to be. Printing with the debugger the POST params before sending the request, shows that the time is indeed in GMT+2:
Params: ["since": "2017-03-15 21:16:04", "chat_id": "86", "username": "testuser"]
However, sending the exact same request, as in my REST client, returns chat messages that have been posted the past 2 hours, like if the iOS app is sending the UTC date instead of my GMT+2 string.
The response in the iOS emulator is the following:
Received data is:
{
"message" : "Messages in this chat:",
"messages" : [
{
"message" : "This is a message",
"chat_id" : "86",
"who" : "1",
"date" : "2017-03-15 21:16:04"
}
],
"error" : false
}
I've been trying to debug this for the past 4 hours with no luck. I don't know if it's the server's fault or iOS' fault, so if anyone can point me to the right direction, it would be very much appreciated. Thank you