didReceiveRemoteNotification 在 Firebase 与 Push 框架一起使用时未调用

didReceiveRemoteNotification not called when Firebase is used along with Push framework

我正在使用 Firebase 进行分析,并使用库进行推送通知。当我使用它们中的任何一个时,都会调用 didReceiveRemoteNotification。但是当我同时使用它们时,didReceiveRemoteNotification 不会被调用。
代码:

didFinishLaunchingWithOptions :

NSString *google_app_id = @"----";
    NSString *gcm_sender_id = @"----";
    FIROptions *o = [[FIROptions alloc] initWithGoogleAppID:google_app_id GCMSenderID:gcm_sender_id];
    o.APIKey = @"----";
    o.bundleID = @"----";
    o.clientID = @"----";
    [FIRApp configureWithOptions:o];  

// Initilization of push framework 

didReceiveRemoteNotification :

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    // This method is not called when Firebase and push framework are enabled at the same time
    // It works fine when only Firebase or only push framework is enabled
    NSLog(@"Push: %@", userInfo);
}

在 Firebase 云消息传递中此方法的文档中说:

If you are receiving a notification message while your app is in the background, this callback will not be fired till the user taps on the notification launching the application.

mb 此方法仅在您点击启动应用程序的通知时调用?

根据我的经验,我用这种方法处理推送:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)())completionHandler {

方法在应用程序处于活动状态时获取有关即将到来的推送通知的信息。 在块中,您必须输入常量以显示您的通知:

completionHandler(UNNotificationPresentationOptionAlert);

还有一个:

(void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {

此方法适用于点击推送通知。 Mb 在这里你正在处理移动到一些特殊的屏幕。

希望我的经验对你有帮助!

这是因为 Firebase 使用 swizzling 拦截 AppDelegate 的方法。

您应该在应用的 info.plist:

中禁用它
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

其实GitHub上有很多关于Push Notification in iOS with Firebase的信息。您可能会在那里找到更多问题的答案。