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

相關問題