Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Enables the ability to support multiple push providers #1128

Closed
wants to merge 11 commits into from

Conversation

shercoder
Copy link

This change only impacts Android

The need for this change came because the project I work has a need to support multiple push providers. We have an internal provider where we manager our in-house push notifications and then there is a need for external/marketing push notifications that we depend on a third-party to deliver.

Since there can only be one FirebaseMessagingService with intent-filter of com.google.firebase.MESSAGING_EVENT, we cannot have a service from Localytics and RNPushNotificationListenerService declared in our AndroidManifest. Android by default will only pick the first declaration.

In order to support multiple providers, a developer can create a custom FirebaseMessagingService that distributes the push notification to providers. Please see this issue I created that explains the problem and the solution in more details #952

Basically this change now allows the developer in need to do the following in their custom FirebaseMessagingService:

private RNReceivedMessageHandler receivedMessageHandler = new RNReceivedMessageHandler(this);

...
...
...

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> data = remoteMessage.getData();

        String from = remoteMessage.getFrom();
       
            try {
                if (from first provider) {
                    receivedMessageHandler.handleReceivedMessage(remoteMessage);
                } else {
                    // pass remote message to another provider
                }
            } catch (Exception e) {
                Log.e(e, "Failed to extract Push Message", remoteMessage.getMessageId());
            }
        
    }

NOTE: There will be no change in behavior in how the current version of this library works and the users who don't need the support for multiple push providers won't have to change anything in their code base and continue to use the RNPushNotificationListenerService as it is.

Testing

  1. For single provider, you can just go through the normal setup as described.
  2. For multiple providers, go through the normal setup for this library but instead use your customer FirebaseMessagingService instead of RNPushNotificationListenerService as mentioned above.

shercoder added 2 commits July 8, 2019 15:40
Exposing handling of received messages without starting the service when
you have a custom firebase service that handles multiple push providers
owinter86 and others added 2 commits August 20, 2019 15:15
The fallback variables defined in the build gradle are all undefined
DEFAULT_SUPPORT_LIB_VERSION
DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
DEFAULT_FIREBASE_MESSAGING_VERSION

(cherry picked from commit fe1da09)
@plus-
Copy link
Contributor

plus- commented Dec 23, 2019

This would also let us localise the messages from the push notification (if anyone know a work around for this, please let me know)

@nchase
Copy link

nchase commented Jan 29, 2020

@zo0r have you seen this PR? Supporting multiple push providers from the npm package would be great 🙂

* upstream/master:
  Update package.json
  Fix undefined fallback variables in build gradle
  Update README.md
  Update package.json
  Update README.md
  Update PushNotificationIOS dependency
  Update react-native.config.js
Updating our forked version to 4.0.0 so we don't get confused with the
version on the original repo
@mysport12
Copy link
Contributor

@Dallas62 it seems like you have been driving the repo forward lately so just wanted to be sure you saw this PR. This functionality would be amazing to have for a number of different projects.

@Dallas62
Copy link
Collaborator

I will take a look ASAP 😉

@Dallas62 Dallas62 self-assigned this Apr 29, 2020
@mysport12
Copy link
Contributor

I will take a look ASAP 😉

Awesome! Much appreciated, and also a big thank you to @shercoder for the PR!

@shercoder
Copy link
Author

Thank you @mysport12 and @Dallas62. This would be a great addition to the lib, one of my former colleague ran into the same problem and I had to point him to my forked branch for the time being.

@Dallas62 Dallas62 changed the base branch from master to dev May 4, 2020 19:19
@Dallas62
Copy link
Collaborator

Dallas62 commented May 4, 2020

Hi @shercoder
Did you have a bit of time to make your changes compatible with the latest version ?
In this PR or another, if not, I will try to take time to reimplement it on dev branch ASAP.

@shercoder
Copy link
Author

@Dallas62 I'm not 100% but I'll see if I can carve some time this weekend. Also, I haven't looked at changes in 0.62 (latest), are there any changes I should be aware of?

@sdenaci
Copy link
Contributor

sdenaci commented May 18, 2020

Hi! I needed to use this library with another push provider on a project I am currently working on, so took a stab at reimplementing @shercoder 's pr back on current dev. Am submitting it back to library in case it is helpful! Here is the pr #1445

@Dallas62
Copy link
Collaborator

Hi,
Since @sdenaci made another PR, I close this one.
Changes will be released soon.

@Dallas62 Dallas62 closed this May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants