0

当应用程序关闭时,我可以运行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]; 

    }]; 
} 

回答

1

据我所知,火力地堡使用TCP连接,通知正在观察一个数据库路径的设备。因此,Firebase无法在后台运行,因为Apple在后台不允许TCP连接。

很遗憾,你试图做的事情是行不通的。

+0

好的,谢谢 但现在我的问题是有没有去从火力点自动发布通知取决于数据库的变化,从控制台 通知跑好 –

+0

哦,在这种情况下,你应该尝试使用火力地堡上触发的功能。以下是可帮助您开始使用的示例:https://github.com/firebase/functions-samples/tree/master/fcm-notifications – TawaNicolas

相关问题