didReceiveRemoteNotification not called when Firebase is used along with Push framework
Asked Answered
U

2

8

I am using Firebase for analytics and a library for push notifications. When I use either of them, didReceiveRemoteNotification get called. But when I use them both together, didReceiveRemoteNotification doesn't get called.
Code :

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);
}
Unbounded answered 29/10, 2018 at 19:19 Comment(6)
How are you registering to receive push notifications?Sublime
@Sublime : The push framework does that. They have their backend. When the framework is initialised, push, app gets registered for push notifications.Unbounded
After you register for push notifications, there are callback methods to let you know if the registration was successful or not, as well as provide you with a push token to use for sending notifications. Have you tried to see if registration is succeeding? Also, what are you doing with the token they give you?Sublime
@Sublime : Registration is definitely successful. I am receiving push notification always. It's just that with both push framework and Firebase, didReceiveRemoteNotification is not called.Unbounded
Have you looked into the UNUserNotificationCenter developer.apple.com/documentation/usernotifications/…Sublime
@Sublime : I did.Unbounded
S
2

This is because Firebase uses swizzling to intercept methods of the AppDelegate.

You should disable it in your app's info.plist:

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

Actually there is a lot of information about Push Notification in iOS with Firebase on GitHub. You probably will find answers for your further questions there.

Sheepdog answered 7/11, 2018 at 20:17 Comment(6)
But that is stopping Firebase Analytics as well. Any way just to disable Firebase push notification ?Unbounded
Does it disable entire analytics, or just some events? May be you can try to call them manually.Sheepdog
I require all analytics to be handled by Firebase, not manually.Unbounded
@Nitish, you require it from me, sir? :D Sorry, I think I can't help. If I was you I would contact Firebase support or just handle those events manually.Sheepdog
That is not what I meant. But I understand your point. Thanks.Unbounded
I understand that it wasn't what you meant, it was just a joke.Sheepdog
S
-1

In the documentation for this method in Firebase Cloud Messaging said:

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 this method calls only when you tapped on notification which launch app?

In my experience I deal with pushs with this methods:

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

Method get info about coming push notification if app is active. In block you must put constant to show your notification:

completionHandler(UNNotificationPresentationOptionAlert);

And another one:

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

This method works with tapping on push notification. Mb here you are working with moving to some special screen.

Hope my exp helps!

Schreck answered 7/11, 2018 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.