Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background message/notification handler never invoked on iOS #137

Open
rutvik110 opened this issue Feb 27, 2022 · 10 comments
Open

Background message/notification handler never invoked on iOS #137

rutvik110 opened this issue Feb 27, 2022 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@rutvik110
Copy link
Collaborator

Description :
When app is open from background by tapping on notification, the notification is not being recieved within the app.

Logs :
2020-10-01 15:58:24.788526+0100 Runner[972:925222] Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

This is something which is occuring just now. I believe prev it was working fine. Something probably related to this

firebase/flutterfire#6290

firebase/flutterfire#3735

@rutvik110 rutvik110 added the bug Something isn't working label Feb 27, 2022
@rutvik110 rutvik110 self-assigned this Feb 27, 2022
@mfreeman451
Copy link
Collaborator

In our case, we have been able to make onBackgroundMessage work on iOS even if the app is terminated. However, this is not the case if the device is in low power mode / has low battery / is locked.

Our current workflow that works only when the device is NOT in low power mode is:

App is in terminated state.
Our backend sends first a data-only message with 'apns-push-type': 'background', 'apns-priority': '5', contentAvailable: true
Device receives the silent data-only message and "awakes" the app. It still doesn't appear in the current apps opened, so it's in terminated state.
Our backend sends a few seconds later our notification+data message, which is now handled by the onBackgroundMessage handler, since the app was awaken previously.
If the device is in low power mode, the step 4 is not handled even when the app has been awaken. We know that the app has been awaken because when we click on the app icon, the splash screen is not loaded, and instead the home screen is already loaded.

However, if we send another notification AFTER the app has missed the previous notification+data message, this one is correctly handled by the onBackgroundMessage. This is what is really strange to me. The handler probably gets awaken aswell when the first notification+data message arrives to the system notification center? Making the handler to work in next messages?

TLDR; If the iOS device is in low power mode and the app is still in terminated state, the onBackgroundMessage is not called for the first notification+data message even when the app has been previously awaken by a data-only message. However, the second notification+data message will trigger the onBackgroundMessage properly


@rutvik110
Copy link
Collaborator Author

@rutvik110
Copy link
Collaborator Author

@rutvik110
Copy link
Collaborator Author

rutvik110 commented Mar 19, 2022

@mfreeman451 Damnn! It's the pusher as I suspected! The handlers from firebase are overridden by the pusher handlers as they should be but they don't have that notification handler implemented yet! :(
I tested by removing the pusher beams package and sent notifications through firebase. Those notifications are handled properly in all the app states!

@rutvik110
Copy link
Collaborator Author

rutvik110 commented Mar 19, 2022

What are the possible things we can do now to get around this?

Some of my opinions :

  1. Move from pusher beams to firebase messaging for sending and handling of notifications. I don't think this would have much big of an impact rn as the migration should be easy to go with.
  2. If for any reason we still want to continue with pusher beams, we can either wait for them to update this which I think won't happen anytime soon seeing the activity on their git repo. Secondly, we could help update that in but that would take our time and efforts and we would have to maintain that specific part.

Wdyt?

@mfreeman451
Copy link
Collaborator

Can you explain what is happening or missing / broken on the pusher side please?

@mfreeman451
Copy link
Collaborator


    public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        // Handle the user interaction with the notification
        // Not Implemented yet
    }

is this it?

@rutvik110
Copy link
Collaborator Author

yah, I think that's it.

@rutvik110
Copy link
Collaborator Author

I didn't look into how it's being communicated to the top level but I'm sure that's the missing bit!

@rutvik110
Copy link
Collaborator Author

Filed an issue in pusher beams for this.
pusher/push-notifications-flutter#23 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants