反应本机远程通知

时间:2020-08-16 09:30:46

标签: react-native firebase-cloud-messaging apex-trigger

我正在尝试基于apex触发器向我的android设备发送移动推送通知,但没有看到通知横幅,但是在控制台中,我可以看到触发了 onNotification 事件,并且可以看到我的有效载荷信息。 我遵循了在react native应用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);`

0 个答案:

没有答案