【问题标题】:What is the most efficient way to check a user is online (Messaging Application)检查用户在线的最有效方法是什么(消息应用程序)
【发布时间】:2014-03-04 07:25:54
【问题描述】:

我们正在尝试开发像 Viber 这样的消息传递应用程序(移动)。我们现在正在查看用户状态(用户是否在线)。我们昨天测试了 Viber 并了解到如果用户关闭应用程序或用户离开网络,其他用户会立即得到它。我的意思是其他用户都知道用户“刚才”在线

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

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

谢谢..

【问题讨论】:

    标签: android ios instant-messaging


    【解决方案1】:

    您对这些协议的工作方式是正确的。如果用户关闭,它会立即向对等方广播他们不再在网络上。

    但就像你提到的,当有人崩溃或失去信号时,这不起作用。通常,您希望继续轮询用户以确保他们仍然在那里。有效率成本,每次轮询之间的等待时间是您应该确定的。在立即获得通知与过于频繁地轮询和占用资源之间需要权衡取舍。

    更新:
    我可能是错的,但我认为 viber/what 可能正在轮询,并且由于它经常轮询,它看起来是即时的。
    我不知道如何在程序崩溃时通知程序,因为崩溃意味着它无法在功能上发送任何类型的信号。所以它必须如此频繁地轮询,以至于它看起来很直接。

    【讨论】:

    • 但如果有人崩溃或失去信号,viber/what app 会立即更新。我想知道这些应用程序实际上是如何工作的。我可以以任何方式实现它,但我关心的是什么是有效的方式。谢谢你的回复:-)
    【解决方案2】:

    在这些方法 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

    【讨论】:

    • 谢谢,但您可能没有理解我的问题。我可以在必要的地方进行更改,但是如果用户应用程序未通知服务器,每个人实际上如何通知状态更改。
    • 您需要通过这些方法向服务器发送状态
    • 你现在明白了吗?
    猜你喜欢
    • 2023-03-09
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 2010-09-29
    • 2011-01-12
    相关资源
    最近更新 更多