How to Receive Push Notifications of an Other App

Receive push notifications on one android app from two Firebase projects

There is actually a part in the documentation about this topic:

Receiving messages from multiple senders

FCM allows multiple parties to send messages to the same client app. For example, suppose the client app is an article aggregator with multiple contributors, and each of them should be able to send a message when they publish a new article. This message might contain a URL so that the client app can download the article. Instead of having to centralize all sending activity in one location, FCM gives you the ability to let each of these contributors send its own messages.

To make this possible, make sure each sender generates its own sender ID. See the client documentation for your platform for information on on how to obtain the FCM sender ID. When requesting registration, the client app fetches the token multiple times, each time with a different sender ID in audience field.

Finally, share the registration token with the corresponding app servers (to complete the FCM registration client/server handshake), and they'll be able to send messages to the client app using their own authentication keys.

Note that there is limit of 100 multiple senders.

I think the confusing but important part here is:

When requesting registration, the client app fetches the token multiple times, each time with a different sender ID in audience field.

In other terms, you'll have to call getToken() passing the Sender ID and simply "FCM" (e.g. getToken("2xxxxx3344", "FCM")) as the parameters. You'll have to make sure that you call this for each sender (project) that you need.

Also, note from the getToken() docs:

This is a blocking function so do not call it on the main thread.

Some additional good-to-knows:

  • It does not auto retry if it fails like the default one.
  • It returns an IOException when it fails.

Get push notification of other App then run code with string of push notification

App A sends a push notification like "David sent 'Our Network is
currently offline. We try to fix it as soon as possible'"

App B then executes a code with the Text of the Push Notification in a
string.

That is POSSIBLE! Given that the App A and B both receive the same remote push notifications.

You can choose to not present the push notification inside App B. through the use of UNUserNotificationCenterDelegate. https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate

And again with that protocol, you can extract the string or whatever data you need from the remote push notification upon receiving it and then present it to the user or don't at all.

How to send notification between two application

You'd probably have to go with something like this:

  1. Create two separate Firebase Projects for each app with FCM enabled. (Project A and B)
  2. Implement FCM for both Apps and generate tokens for each project to both apps (i.e. App A has tokenA and tokenB, App B has tokenC and tokenD). See my answer here.
  3. Store the tokens to the corresponding servers.

From there, the flow of interaction should be something like:

App A > sends data > Server A // (contains App B's tokenC)
Server A > sends notification > App B // (by using tokenC)

and vice versa:

App B > sends data > Server B // (contains App A's tokenB)
Server B > sends notification > App A // (by using tokenB)

That's pretty much the general idea.

With all that said, "how can I achieve that in other cases?" is too broad of a question.

Can I read others push notifications on iOS?

TL;DR. No


APNs delivers remote notifications based on a token, generated by an app. The token at each moment of time is unique to the app instance, installed at the specific device. Only the app instance associated with the token is delivered with corresponding remote notifications.

Swift: Detect and Cancel Another App's Notification

No there is no such feature on iOS. Apple goes to great lengths to prevent 3rd party apps from altering the behavior of the system or of other apps.



Related Topics



Leave a reply



Submit