I have the following question about creating a chat room. The message model has a creationTimeStamp property, it is assigned when the user sends messages from the device. When another user (or users receive this message), at the moment I do not change this property for the time when the message is received locally on the device. Messages I save locally in Realm. The problem is that for example the message was sent at one time to the first users, but because of the slow Internet connection, the second user already had time to send his message (or messages), then the second user appears this message after his sent message to ChatViewController, But when he leaves this controller and goes back, his message will be displayed last, and not the message of the first user, since when I take messages from Realm, I sort them by creationTimeStamp. So I want to learn the best practice of saving time stamp, for this case.
Can it be better to change the creationTimeStamp when the message is received on the device? But there are also problems here if the user has more than one device. Although I think that this is how messages are stored in iMessage, because they have the synchronization between devices, I attach screensots of the same correspondence, when messages were created quickly.
Unfortunately I don't have best practice for you, only some thoughts.
I think what you want to achieve is quite hard to achieve without inconveniencing users. What I mean is that due to internet connection speed, different users may all have different point of view about timing of your messages. You could correct/sync their view after some time using creationTimeStamp to resort messages, but then messages on screen will be reordered which could be annoying.
I guess you could think about different approach - is it that important that all users have the same timeline view? When some time ago we were implementing a group chat we agreed on the notion that single user can have different timeline view. Then we used recievedTimeStamp for sorting, for local messages receivedTimeStamp is the same as creationTimeStamp. It worked out pretty well for us, but of course you can have different requirements.
Related
I'm considering adding a messaging feature to an iphone app. The idea being that given a user-based IOS app, a user may have a list of other users. He may then want to send one a message. A straight network call could accomplish this, but it misses a couple pieces:
1) The ability for a logged in user to "listen" for incoming messages without necessarily polling the server every few seconds. Does IOS support an open socket connection for listening somehow?
2) The ability for the server to detect presence of users (when they are logged in, active and listening; and immediately if they connect/disconnect)
3) the ability to detect typing, if possible
I've heard this can be achieved in javascript apps with socket.io libs, and wondering what equivalent tools exist in IOS natively? Or should a webview with JS be attempted?
EDIT:
Push notifications will likely be leveraged for offline use, but am not sure they can be a substitute for all the real time interaction.
EDIT2:
Found this SocketIO tool for IOS, but have no experience with this. It is a possibility though.
https://github.com/pkyeck/socket.IO-objc
For number one you should look at this tutorial:
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
It uses pushnotifications to detect incoming messages.
the other two parts are probably timing, just say a user is active for 2 min since their last activity. And every time they use something in the app or poll the server you update the time and make them active for another two minutes or so.
And you can detect typing if something is typed into the textfield. UITextField has a onChanged method. You could also start a timer to detect changes between a certain amount of time. So it doesn't say typing if someone just left their textfield filled but didn't send the message.
Hope this helps.
I'm developing an application which holds a list of objects.
The user should be able to favorite some of these objects, which then gets saved for easy access. Simple enough, right.
However, in addition to that, I want it so that the application notifies the user (using a notification, like when you get a new SMS), whenever one of the favorited objects have had something changed (in my application the objects represent a pub, and a change to the pub is when it has a new event scheduled). The change is done on a remote server, using a webpage.
When my app is active I can just poll the server every few minutes and compare the properties of the object, and if I see a change notify the user.
But how will I do to make this work when my app is NOT in the foreground? I want the user to get a notification even if he/she is not currently running my app.
The app does not have any login-functionality, so I can't send out specific push notifications to specific users. So the only thing the server might have access to is perhaps the device ID. I.e. there is no real way for the server to know which favorites a device ID holds.
Is there some smart way to do this? On Android I can just use polling but as iOS doesn't allow code to run in the background in the same way I don't really know how to do.
All help greatly appreciated. Even if it's just a "I don't think that's possible".
Just create a table that associates device ID with favorites. When a favorite changes, send that device ID a push notification
The user is the device ID
As I understand for the moment, the location and time sensitive passes in Passbook only support time and/or location based notifications. So at the correct time and location, the user will get a notification for the pass.
I was wondering if these properties also can be used to change the pass. For example, if you are in some specific store, the coupon provides a 50% reduction instead of a 20% reduction. If it is not possible to do this locally on the iOS device, is it possible to send a request to the server based on location and/or date to achieve the same thing?
Sorry to be the bearer of bad news, but it's not possible to accomplish this.
Firstly, the data within the pass is fixed at any point in time. As you've said, it can be fixed to a list of locations and/or a date.
Secondly, the pass cannot communicate with a server except to request an update in response to a push notification. This means you will never know where a pass is.
The only option way to achieve something like this would be to generate passes using an app that is location aware, but I don't think this is what you're after.
You can send a push update to a Pass at a specific time. This way you can (for example) convert a 10%-off coupon to 20%-off on Fridays (and then switch it back after Friday).
After a user has initially 'Added' your Pass promotion into their Passbook you can update it at any time without requiring the user to 're-approve' your update.
Your server does not know when a Passbook user has triggered a location alert - otherwise you could track their movements via Passbook. Apple does not want their customer's security to be compromised in this way.
However, you could issue a coupon that is normally 20%-off (for most stores, or online) but that the location alert for a specific store said 'Get 50% Off at this store'. When the customer comes in to have their Pass scanned & activated, your server will then know the customer's location and can apply the 50% reduction.
From what I can tell, this is not possible, but I wanted to ask in case there were any potential workarounds that have cropped up recently.
Ultimately, I want to programmatically send a message (of some kind) to whoever is calling (while my app is active).
Thank you for any help.
Not possible. Neither is programmatically sending a text message (assuming you mean sending a message from the user's phone).
What I would like to know is whether there is anything wrong (in terms of the law, and App Store guidelines) with storing information about your application, and broadcasting it to an online location for gathering.
Specifically, an application which would normally not connect to the internet, connecting when it starts up and storing usage information like time of day, the device ID, and how long the person uses it for.
I'm guessing this sort of behavior is fine so long as you get the users consent first?
It’s fine if you ask the user first and give him an option to turn this feature off. We were once spanked out of the App Store simply for uploading a new game high-score record without a cancel button. It’s quite a long time and the rules might have changed, but better safe then sorry and your users will like the confirmation screen, too.