Payal Lodhi
Payal Lodhi

Reputation: 1

React native remote notification

I am trying to send a mobile push notification to my android device based on apex trigger, and I didn't see notification banner but in console I can see onNotification event fired and I can see my payload info. I have followed In react native app react-native-push-notification library, all changes are done as per the document mention here https://www.npmjs.com/package/react-native-push-notification.

updated MobilePushServiceDevice whenever user open the with token and service type

On FCM created the project and follow this document https://firebase.google.com/docs/cloud-messaging/android/client

Salesforce create connected enable push notification added server key

here is react code

    const notification =  PushNotification.configure({
    // (optional) Called when Token is generated (iOS and Android)
    onRegister: function (token) {
      //Send this token to salesforce
      let createPayload = {
         ServiceType: getSystemName() == 'Android' ? 'androidGcm' : 'apple',
         ConnectionToken: token.token
      };
      // register device with salesforce
       
    },
  
    // (required) Called when a remote is received or opened, or local notification is opened
    onNotification: function (notification) {
      console.log("NOTIFICATION:", notification);
      notification.finish(PushNotificationIOS.FetchResult.NoData);
    },
  
    // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
    onAction: function (notification) {
      console.log("ACTION:", notification.action);
      console.log("NOTIFICATION:", notification);
  
      // process the action
    },
  
    // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
    onRegistrationError: function (err) {
      console.error(err.message, err);
    },
  
    // IOS ONLY (optional): default: all - Permissions to register.
    permissions: {
      alert: true,
      badge: true,
      sound: true,
    },
    visibility: 'public',
    // Should the initial notification be popped automatically
    // default: true
    popInitialNotification: true,
    senderID: "1019984307481",
    

    requestPermissions: true,
  });

here is my apex code

    `Messaging.PushNotification msg = new Messaging.PushNotification();
     Map<String, Object> androidPayload = new Map<String, Object>();
     Set<String> userSet = new Set<String>();
     androidPayload.put('title', idVSnickname.get(cbuId)+' assigned you a task');
     androidPayload.put('message', subject);
     androidPayload.put('parentId', str[4].trim());
     androidPayload.put('id', str[0].trim());
     userSet.add(accIdVSuserId.get(accId));
     msg.setPayload(androidPayload);
     msg.send('Mimit', userSet);`

Upvotes: 0

Views: 235

Answers (0)

Related Questions