检查用户在线的最有效方法是什么(消息应用程序)

时间:2014-03-04 07:25:54

标签: android ios instant-messaging

我们正在尝试开发像Viber这样的消息应用程序(移动)。我们现在正在讨论用户状态(用户是否在线)。我们昨天测试了Viber,并了解如果用户关闭应用程序或用户离开网络,其他用户立即获得它。我的意思是其他用户得到了用户在线''片刻'

我知道如果用户更改其状态,或者用户关闭了应用程序,则事件可以向服务器发出请求并通知用户现在不在线。然后,服务器使用推送方法通知每个人(相关用户)该消息。但是,如果用户退出网络(禁用wifi /蜂窝电话),每个人(相关用户)如何获得通知?

有效的方法是什么?有参考链接吗?

谢谢..

2 个答案:

答案 0 :(得分:0)

使用这些方法appdelegate.m

更改在线/离线按钮的颜色
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

这适用于ios

答案 1 :(得分:0)

你对这些协议如何运作是对的。如果用户关闭,它会立即向同伴广播他们不再在网络上。

但是就像你提到的那样,当有人崩溃或失去信号时,这不起作用。通常,您希望继续轮询用户以确保他们仍然在那里。这是一种效率成本,您在每次轮询之间等待的时间是您应该确定的。在过于频繁地通知与投票之间以及吸收资源之间存在权衡。

更新:
我可能错了,但我认为viber /可能是轮询,因为它经常轮询它看起来像是立竿见影的。
我不知道如果它崩溃会如何通知程序,因为崩溃意味着它无法在功能上发送任何类型的信号。因此,它必须经常进行轮询才能立即进行轮询。