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];
}];
}
好的,謝謝 但現在我的問題是有沒有去從火力點自動發佈通知取決於數據庫的變化,從控制檯 通知跑好 –
哦,在這種情況下,你應該嘗試使用火力地堡上觸發的功能。以下是可幫助您開始使用的示例:https://github.com/firebase/functions-samples/tree/master/fcm-notifications – TawaNicolas