Detect when user leave my facebook application - facebook

I am developing a Facebook WEB application and I want to know who is currently on line.
How can I detect when a user leave/close my application to change the user flag to offline.

I assume by leave/close your application you mean navigate to a different webpage or close the browser?
The simplest way to achieve this, would be to periodically send a poll back to your webserver using an ajax connection and a javascript timer.
When a user disconnects from your app by closing the browser or changing webpage, the polling would stop happening.
A script running on your server would periodically check the timestamps of the polls of 'online' users, and if it finds one that's no longer up to date, mark the user as offline.
The wikipedia page on Comet (programming) is probably a good place to start
http://en.wikipedia.org/wiki/Comet_(programming)

Related

Time protection algorithm for IOS app without using internet

I need some idea about this problem. I made an application which has login and logout functionality. I need to seek a solution when people logout the system, they new user must allow only after two hours.
I can do it with using internet. It is so basic. I can take logout hour, and when user tries to login, I can check the hour on internet but I don't wanna use this solution because, there is no guarantee for every devices have internet.
I can take offline clock from phone. However, in this time, user can change the time and pass the protection quickly.
Is there any idea about this solution? How can I solve it in IOS and swift?
You can listen to UIApplicationSignificantTimeChangeNotification if your app is in foreground/suspended state. But if your app is killed, you won't get this notification.
So, the best way to ensure that user doesn't login in the next 2 hours is to rely on a source of truth that the user can't change i.e. your backend.
Store the time when the user logs out.
Ask your backend for the current time on every launch
Compare it with the the logout time when user tries to login again.

How to check user is using my application facebook

I want check how to know user is using my application facebook
Example: One user go to application page, i set user online, when user close application page, i set user offline
Thanks.
If you haven't heard from a user for some time, chances are that he closed a page with your app.
Memorize last time a user did anything in your app, and set a timeout. If N minutes later there are no new actions, you mark him offline.

iPhone HTML5 website on homescreen with jQuerymobile offline splash page?

How do I go about loading a splash to the user if they are offline? I want it to show after the initial loading image, I have a page called gone-offline.jsp but how to detect if user is offline on mobileinit?
I'm not using phone-gap
You need to decide what offline means to your business scnenario. This may sounds silly, but it depends on what your app wants to do. For example:
Does your app want to go offline when it is actually offline and can't reach other websites, or does it want be in offline status when it can't access your webservice.
Assuming you want to test that there is no connection to your webservice I would recommend the following:
1) Make an ajax call every x number of minutes to your webservice to check if it is still online
2) make a common method that handles time outs if your application thinks its online and is offline.
3) make it so that when your application is offline, it is trying to get back online in the background by doing a similar step to step 1.
To do ajax with JQuery see: http://api.jquery.com/jQuery.ajax/
Note that if you require cross domain json (you may or may not) then you will need to investigate CORS/JSON-P/XSS with iframes.
it's very simple using javascript.
if(navigator.onLine)
{
//online code here
}else{
//offline code here
}
(done with jQ mobile)

Apple Push Notifications

I'm building an app that checks as site every 15 minutes for changes. I can do this fine in the app, when it's open. But how do I go about doing this while the app is in the background?
The trouble is I don't think I can use the Push Notification Service. The page on the site which is being checked, requires the user to be logged into the site. Because there is a cookie jar for each app, the user logs into the site through a UIWebView at the beginning and then once logged in, the site is polled every 15 minutes using NSURLConnection and receives the data for the logged in user because of the cookies created at login in the webview. I don't believe there is a way to do this on a server for many different users? And if there was wouldn't the user's site username and password have to be stored on my push server which is a huge no.
So can I use task completion, or is it possible to access a page that only appears correct when the correct cookies are present from a server and then use push notification.
Unfortunately there is no way to get the cookie from a UIWebview. And task background completion can only run for 10 minutes.
I'm not sure what kind of website you are trying to access, but if you can replicate the login using a NSURLConnection you can retrieve the cookie using NSHTTPCookie. Then store the cookie data on your server and then access the web site from the server with the "Set-Cookie" header to check the content for changes.
This, of course, depends on how long the cookie lasts (expires).

starting iChat session in iPhone from web app

This is really just a "what-if" type question, so forgive me if it is either ridiculous or ridiculously easy...
I have a client whose site offers a "chat with a consultant" option that you see on many sales and support sites. We were wondering if there was a way that iPhone users (or any user, in theory, but mostly iPhone) could click this option and after giving the basic form info (name, question,etc) the actual chat itself could open up in the chat client.
Is this as simple as the "click here to send me an AIM message" syntax?
The XMPP (jabber) server is Openfire and the webchat uses the Fastpath plugin. Would this feature need to be enabled deeper than the page's HTML/PHP? Does the server/plugin need to modified as well?
Would this threaten the security of the XMPP server (which is behind a firewall and can only be accessed externally via the above plugin)?
Does this even sound like something that iPhone users would appreciate, or would it simply be confusing/obtrusive?
Sorry for the objective last question, but I'd hate to spend time on this only irritate users.
Referrals to resources and documentation welcome. I'm not looking for someone to walk me through the whole thing, I just want to get an idea of it can be done and where to start reading.
I'm a little confused by what you want to do - the user fills out a form on a web site and then they are put into a "chat room" on their iPhone?
This is possible. However all of them require that the user has already installed your app, so it may be a hurdle to what you are trying to do.
However if it's using a pre-existing chat service (such as AIM), you may already be OK if the user already has a chat client installed on their iPhone. You could launch the app using custom urls or push notifications - however, this is assuming that the app developer has enabled such hooks, and if so if they are published.
If you want to go with your own client, if the user is filling out the form on the iPhone, then on submission you could redirect them to a custom url for your application. From mobile Safari, this will directly launch your app. Note that the user must already have the app installed for this to work, or else they'll see an error, and it won't be a particularly user-friendly one.
Another way, if the user is filling out the form on their computer, is via push notification. Again, they must first have the app installed. They would receive a notification that, on acceptance, launches your app.
The final way, if the user is filling out the form on their computer, is that they would have to download your app first and run it, so that it could communicate with a desktop client of yours via network services.