【问题标题】:Keep a Firebase listener in memory when the app is closed关闭应用程序时将 Firebase 侦听器保留在内存中
【发布时间】:2017-07-27 13:50:37
【问题描述】:

我可以在应用关闭时运行 firebase 监听器,这样我就可以在不使用后端发送通知的情况下推送本地通知 我也可以根据数据库中firebase的变化自动从firebase推送通知吗 我在后台运行它,所以我可以推动

- (void)applicationDidEnterBackground:(UIApplication *)application {

    FIRDatabaseReference  *ref = [[FIRDatabase database]reference];
    [[[ref child:@"classes"]child:@"classA"]observeEventType:FIRDataEventTypeChildChanged withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
        FIRDataSnapshot *child;
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        if (localNotif == nil) return;
        NSDate *fireTime = [[NSDate date] addTimeInterval:3];
        localNotif.fireDate = fireTime;
        localNotif.alertBody = @"Alert! from back ground";
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    }];
}

【问题讨论】:

    标签: ios objective-c firebase firebase-realtime-database firebase-notifications


    【解决方案1】:

    据我所知,Firebase 使用 TCP 连接来通知正在观察数据库路径的设备。由于这个原因,Firebase 无法在后台运行,因为 Apple 不允许在后台使用 TCP 连接。

    很遗憾,您尝试做的事情不起作用。

    【讨论】:

    • 好的,谢谢,但我现在的问题是从 Firebase 自动发布通知取决于数据库更改,来自控制台的通知运行良好
    • 哦,在这种情况下,您应该尝试在 Firebase 上使用触发函数。这是一个可以帮助您入门的示例:github.com/firebase/functions-samples/tree/master/…
    猜你喜欢
    • 2017-06-27
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 2021-08-02
    • 2018-01-01
    相关资源
    最近更新 更多