当Firebase与Push框架一起使用时,不会调用didReceiveRemoteNotification

Nit*_*ish 6 objective-c apple-push-notifications ios firebase

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 
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)

kel*_*lin 2

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

您应该在应用程序的info.plist中禁用它:

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
Run Code Online (Sandbox Code Playgroud)

实际上,GitHub 上有很多关于iOS 中使用 Firebase 推送通知的信息 。您可能会在那里找到更多问题的答案。