Firebase PresenceManaging iOS

 呆瓜. 发布于 2023-01-19 09:33

我正在实现一个基于firebase文档的系统:

[connectionMonitor observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    if([snapshot.value boolValue]) {
        // connection established (or I've reconnected after a loss of connection)

        // add this device to my connections list
        // this value could contain info about the device or a timestamp instead of just true
        Firebase * con = [[Firebase alloc]initWithUrl:[NSString stringWithFormat:@"%@Users/%@/connections/", urlString, currentUserId]];
        Firebase * newConnection = [con childByAutoId];
        [newConnection setValue:@YES];

        // when this device disconnects, remove it
        [newConnection onDisconnectRemoveValue];
    }
}];

如果用户完全断开连接,哪个工作正常,但那是我的问题.

我使用这个系统来查看用户是否在线.如果他们不在线,我会触发推送通知.如果用户关闭应用程序,firebase不会断开连接,但它也不会收到更新,因此在另一端,用户看起来仍然在线.要正确设置firebase onDisconnect值,用户需要完全关闭应用程序.

我通过添加以下内容解决了这个

- (void)applicationWillResignActive:(UIApplication *)application
{
    [Firebase goOffline];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [Firebase goOffline];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
   [Firebase goOnline];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [Firebase goOnline];
}

这是正常的行为,还是我做错了什么?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有