Here's how I would attack the problem:
- Have the app assign a unique ID to the IOS device. (I'd save it in NSUserDefaults)
- When the app starts check a url to get a response (ie: check if the user is online)
- Connect to a server and if it hasn't already, compare the unique key with other entries
- If there is no other entries in the entire entry history set another NSUserDefault (BOOL) to tell the app it never needs to check again.
- This unique key now becomes a 'log-in' of sorts and can be transmitted to the server
- (optional) have the user fill out information so the server can relate the key to a person/stats/whatever information, rather than just a lonely key and upload this information (if this is done, AFAIK, apple requires you to warn users that their information is being taken.)
- Have the device send a message every so often to the server to tell it 'hey, I'm still alive'
- Have the server cycle through every so often (I'd say ~ double the time the IOS device sends the 'I'm alive' message. ie: if the device tells the server every 5 seconds it's still online, have the server check the list and responses every 7.5 - 10 seconds) and remove the list of online keys using information gathered in a response table. If the IOS device hasn't sent the message when the server cycles through, it mustn't be online.
I can see where you are going with time stamps, however with multiple users around the world with multiple connections, you would have to be lenient with your date & time entries and checks (however you seem to already have that in mind) because it takes longer times for some users' internet than others to respond.
EDIT: just saw your lat bit about instant messaging. From my experience if you are on a mobile device it isn't always instant (it seems to me that when I open up a chat conversation to someone on my phone over Facebook, their online status is not updated until I send the message/every set amount of time). Sometimes I will receive messages 30 seconds to a minute later on my phone after it has reached my computer. But this seems to be prioritised (ie: if I'm having a big conversation with someone with lots of messages going back and forth, communication is very instant)-just thought I'd share.