0

我正在尝试基于 apex 触发器向我的 android 设备发送移动推送通知,但我没有看到通知横幅,但在控制台中我可以看到onNotification事件被触发并且我可以看到我的有效负载信息。我已经关注了在反应原生应用程序react-native-push-notification库中,所有更改都按照此处提到的文档https://www.npmjs.com/package/react-native-push-notification完成。

每当用户使用令牌和服务类型打开时更新 MobilePushServiceDevice

在 FCM 上创建了项目并遵循此文档https://firebase.google.com/docs/cloud-messaging/android/client

Salesforce 创建已连接启用推送通知已添加服务器密钥

这是反应代码

    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,
  });

这是我的顶级代码

    `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);`
4

0 回答 0