How to send a notification to a specific platform?

I want to send two different notifications on Android and iOS. I want to send a notification on iOS, so iOS displays a nice notification. For Android, I want to send a data message, so I can process the notification on Android as well as in the background (because I do not receive the callback in the background and I do not want to process it myself).

I looked through the documents, but could not find anything about sending to a specific platform. How to do it?

And other suggestions on how to do this are welcome, but keep in mind that I specifically want to handle the notification myself through an Android callback (onMessageReceived)

+4
source share
2 answers

Update . The last function was added for FCM, which makes it possible to provide certain parameters for specific platforms, called Platform Overrides :

Configuring messages across platforms

Messages sent by the FCM v1 HTTP protocol can contain two types of JSON key pairs:

  • A common set of keys that will be interpreted by all application instances that receive the message.
  • platform-specific blocks that are only interpreted by application instances running on the specified platform.

, , , . , .

  • , all - iOS, Android web

, , message.notification.title, message.notification.body message.data.

  • , ,

, , ; . , iOS , Android, : iOS .

, , . , ; , . , - - , Android , iOS .

:

v1 , . , :

  • Android -, APNs (iOS)
  • Android iOS - click_action category .
{
  "message":{
     "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
     "notification":{
       "title":"Match update",
       "body":"Arsenal goal in added time, score is now 3-0"
     },
     "android":{
       "ttl":"86400s",
       "notification"{
         "click_action":"OPEN_ACTIVITY_1"
       }
     },
     "apns": {
       "headers": {
         "apns-priority": "5",
       },
       "payload": {
         "aps": {
           "category": "NEW_MESSAGE_CATEGORY"
         }
       }
     },
     "webpush":{
       "headers":{
         "TTL":"86400"
       }
     }
   }
 }

. HTTP v1 , , , . , , . Build Send Requests.


, , , , . , . - "".

, , (, topics/(Android/iOS)_<Your App Name>), .

, Firebase DB, node:

/pushTokens
  /android
    /{userId} : string
  /ios
    /{userid}: string

.

+3

Android Development. Laravel . .

Android:

FCM::sendTo($tokens, $option, null, $data);

null . null databuilder ($ data), onMessageReceived, .

iOS:

FCM::sendTo($tokens, $option, $notification, $data);

$notification. , iOS .

0

Source: https://habr.com/ru/post/1684734/


All Articles