Handler远程通知后台

Handler Remote Notification background

我现在有这个问题,我需要在后台处理应用程序推送通知的信息,我的意思是,即使不点击通知。 这意味着这个 application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 必须在后台调用! 这是我的代码

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{

    NSLog(@"full message %@", userInfo);
    NSDictionary *aps = [userInfo objectForKey:@"aps"];
    NSLog(@"full aps %@", aps);
    NSString *custom = [userInfo objectForKey:@"custom"];
    NSLog(@"full custom %@",custom);
    completionHandler(UIBackgroundFetchResultNewData);
    [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationRemote" object:nil userInfo:userInfo];
}

我真的需要处理这些信息,以便每次我有任何通知时都将其保存到本地,无论我是否点击推送通知。

我搜索并发现我的负载需要可用内容,但我无法在 Firebase 控制台通知中找到它。

是的,您需要有效负载中的内容可用密钥才能静默推送通知。

关于 FCM 的更多信息,你可以看到这个link:

您可以使用 FireBase Cloud Function 创建有效载荷,Fire Notification.You 可以处理 Firebase 实时数据库中的事件。 实时数据库支持 onWrite() 事件,该事件在指定数据库位置创建、销毁或更改数据时触发。 请参考本教程了解详细信息,这可能对您有所帮助 https://code.tutsplus.com/tutorials/serverless-apps-with-firebase-cloud-functions--cms-28557