Issues with delivering chat messages to offline user - ios

I have an issue delivering messages in chat when one of the users goes "offline".
When 1-on-1 chat is initialized and two users are chatting, messages are being delivered and everything works great, but when app of one of the users goes background, the other one keeps messaging. It looks like messages are being sent, saved into history and cache (I log it), but when the other users goes back online and retrieves history — these messages do not appear.
In the logs I see them coming with the delay after the app restarts:
2013-03-13 01:14:42.983 MyApp[2314:1103]
QBChat/xmppStreamDidReceiveMessage:
<message xmlns="jabber:client" id="0" type="chat" from="XXXXX-XXXX#chat.quickblox.com"
to="XXXXXX-XXXX#chat.quickblox.com">
<body>I try again</body>
<delay xmlns="urn:xmpp:delay" from="chat.quickblox.com" stamp="2013-03-13T07:58:14.455+0000">
Entire messaging process is built using code from SimpleSample chat
(Also, I do not use Push Notifications yet).
Can you, please, advise me something on this issue?
Thank you.
UPDATE: After reinstalling the app, message history with the user isn't retrieved, that means, I guess, the history I was talking about was stored in cache. Seems like I have issues in retrieving history from server. I have tried 'message.delayed = 1' in 'ChatDidReceiveMessage', but it didn't help.

You have to logout from Chat when you go to background and login again when you go to foreground.
Your messages will be received OK in this case

Related

Ejabberd offline messages

I have set up a chat server with Ejabberd, It is working fine. Messages are getting sent from one user to another user. Problem is that when the receiving user is offline, Sender messages should get stored and get delivered to receiver when he comes back to online. But offline messages are not getting delivered. I have not changed anything in configuration file because it looks already configured for the offline storage and offline message delivery. Do I need to make any other changes apart from the below lines?
ejabberd.cfg:
{access, max_user_offline_messages, [{5000, admin}, {100, all}]}.
{mod_offline, [{access_max_user_messages, max_user_offline_messages}]}
Please update your ejabberd from 2.1.10 to 16.10, as you using the older version certain func. may not work as expected.

iOS: Unable to fetch Offline messages for XMPP Chat

I am facing an issue with the presence status, following the documentation and XMPPframework example code. I have written a chat application.
Problem : When the user 1 & 2 are online I get the status successfully and they can chat with each other. However when the user 2 goes physically offline via (Wifi OFF / 3G Off) User 1 is not getting the offline status from XMPP and hence what ever messages are sent from that instant of time are lost when the user 2 comes online.
It seems since the user 2 is not notified or stored as offline in XMPP and hence its not storing the offline messages to push back to user 2 when it comes online.
I have tried to resolve this by explicitly writing a [goOffline] call to XMPP, however the call is shown in 'SEND log' for 'user 2' but not received in 'RECV log' in user 1 from XMPP, due to which the message are lost in between.
Also tried with other sources replies.
Set status for presence available and send XMPP
priority changed with values non-negative
XMPPArchiving work but this is not what I wanted.
Server side Mod_zero push enables but get only first message push notification sometimes.
Setting limit on ejabberd.cfg file for users and offline message limit.
request for offline message pull.
Can anyone help me with this?
This is very typical situation where client losses network but server can't detect that it is offline.
To detect status of each client, server need to send PING packets to every client and wait for response.
If client responds then fine otherwise server will mark that client as offline and every other online client will be informed automatically.
Here is PING Module implementation for ejabberd XMPP Server (hope you are using ejabberd server):
mod_ping:
send_pings: true
ping_interval: 10
timeout_action: kill
ping_ack_timeout: 10
This has to be written in ejabberd.yml configuration file.
At client side also we need to enable ping module to respond to server pings as:
private var xmppPing: XMPPPing?
xmppPing = XMPPPing()
xmppPing!.activate(xmppStream!)
This code has to be written while we setupStream() for iOS.
For detailed info, please go through mod_ping documentations.
Sounds like your problem is at server level. The server thinks that the user is online so it sends the message but nobody gets it. This does not really have a simple solution.
1.
The best solution would be delivery receipts. Where basically when the message is sent to your client, your client returns a confirmation of delivery receipt. If the server does not get that receipt it would resend the message every n time. Depending on your XMPP server you might find a already made solution, of not you would have to roll out your own.
2.
A possible hack would be to have your server always store and deliver last 10 messages and then at client side you discard repeated... This also depends on your server implementation. XMPP MUC and PubSub have resources along these lines.
For a long term scalable solution, you'll need to deal with this both at server and client level.

iPhone app development. How does an app like snapchat send data from user to user?

I'm just starting to get into app development and have just been learning the uses of Xcode and Objective-C language. Just wondering how an app like snapchat or any other app can send data from one user to another. General answers would suffice just to better my understanding.
How do they test this functionality?
How can they connect peer to peer and send data from one phone to another? Is it all accessed in one database that the app connects to everytime that it pulls down?
When you sign up for an app like this with a registered account is that information stored on the iphone?
Well there are two ways data can be sent to a device. One is the device polls the main server periodically. This can be seen in a pull to refresh scenario. The other is the server can send a push notification to the specific phone and app which causes the data to be received by the device and displayed however the programmer wants. So device to device is essentially one person sending something through a web service call to your server. Your server them packages that information into a Json payload and sends a push notification to the recipient. It seems like its device to device because its so quick, but it requires that you have a server in the middle and of course your server is really sending the push notification to Apple's push server, so there really are two servers involved.
How do they test this functionality?
I would try to do this with real devices, and/or using a network sniffer tool to inspect the send packets.
How can they connect peer to peer and send data from one phone to another? Is it all accessed in one database that the app connects to everytime that it pulls down?
Someones sends you a snap
your app will ask the database every ...min or when you reload if there's something new to load, and gets it from the database if there is something new
When you sign up for an app like this with a registered account is that information stored on the iphone?
Connect to snapchat
get a snap from someone and wait till you can view it
start airplane mode and see if it loads, if it does there are files (temporarily) stored on your iPhone.

Register for SMS Notification

Can I register for SMS Notification through my application? All I want is to increase counter in my application when user is doing any SMS out of my application.
The sandbox nature of apps on the iOS platform prevents you from seeing what the other apps are doing. You will need to track what you are setting up with your MFMessageComposeViewController as you are helping them prepare to send an SMS message. But you can't tell if they added other recipients or deleted the ones you set up originally.
You can use the delegate to find out if the message was successfully sent, cancelled, or failed.
You get the result in messageComposeViewController:didFinishWithResult:
Nice try NSA!
Seriously though, SMS (text messaging), phone calls and e-mails are all "walled gardens" on the iPhone. This functionality belongs to the OS only, and there is little to no chance that Apple will ever open it up to developers. The other term thrown around is "sandbox" and these system level apps are in it.
Think about the potential consequences if every app could access your text's, e-mails and phone calls (even if it was just the meta-data). What kind of a world would it be when Candy Crush launched an alert the next time you played that said "We noticed you've been getting a lot of messages from Jennifer recently, would you like to invite her to play candy crush too?"

Iphone - Notify from the server to the client when an event occurs

im stuck in a situation
SITUATION : I have a situation wherein i answer some questions and get points according to the answered questions. if my points become say 10 i win some gift using a QRCode. (there is a qr code that is generated to the user, and when the qrcode is scanned from someother device which has a scanner app or any other scanner, it gives a link to that online store. This link can be opened from any browser.) The gift is accessed from some online store by scanning the QRCode which gives a link to that online store with some unique id and when the gift is accessed/taken the server is notified that the gift is accessed/taken from that online gift store and the QRCode status is updated to invalid on the server database. Now once the server gets the notification that the gift is being accessed/taken, the server should immediately notify my iphone app that the gift is received so that i can immediately show another congratulations image or something.
POSSIBLE SOLUTION : i thought of one possible solution wherein i check upon the qrcode access status change on the server every say 60 secs and display the image accordingly. I dont know how efficient/correct this way would be though.
ISSUE : but before i refuge to the above solution, i want to know, can this notification happen from the server without my app trying to call or fetch the update from the server? I mean, my app comes into the picture only after the server sends a notification in the form of a msg or some xml or something..
Any help would be deeply appreciated.
You can open a connection to your server using CFReadStream, add the stream to your runloop and set up a callback function. Whenever the server writes data to the open connection, your callback will fire and you can then read from the stream to get the data the server sent
More info here: https://developer.apple.com/library/mac/#documentation/Networking/Conceptual/CFNetwork/CFStreamTasks/CFStreamTasks.html
You could try to check Push Notifications. But it's impossible to determine on server side if notification was received on client side or not (if you won't implement it by yourself, but you'll probably wont cover all the possible situations, like when your app is not launched and notification came).
you can try to use XMPP protocol, which is most commonly used for chats/mails, where the changes in the server is notified to the clients.
Apple Push Notification Service is meant to solve these types of situations.
Hope it helps:
Apple Docs: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9
There is a nice tutorial: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
Video tutorial: http://www.youtube.com/watch?v=cKV5csbueHA&feature=relmfu

Resources