如何设置 Lambda 以使用 Pinpoint 的 APNS 沙箱?

问题描述

我在使用 AWS pinpoint 从 lambda 远程发送推送通知时遇到了一些问题。

在我的应用程序中,我有以下代码

    PushNotification.configure(awsconfig)
    PushNotificationIOS.addEventListener('registrationError',console.log)

    PushNotification.onRegister(async token => {
      console.log('in app registration',token)
      PushNotification.updateEndpoint(token)
      setRegistrationToken(token)
    })


    PushNotification.onNotification(notification => {
      console.log('in app notification',notification)
      if (Platform.OS === 'ios') {
        notification.finish(PushNotificationIOS.FetchResult.NoData)
      }
    })

    PushNotification.onNotificationopened(notification => {
      console.log('the notification is opened',notification)
    })

    const endpointId = Analytics.getPluggable('AWSPinpoint')._config.endpointId
    console.log(`endpoint ID: ${endpointId}`)

    if (Platform.OS === 'ios') {
      PushNotification.requestIOSPermissions()
    }

代码运行良好,我可以获取记录的令牌,转到精确控制台,然后通过选择“设备令牌”和“APNS 沙盒”发送“测试通知”。

在那之后,我设置了我的 lambda 并添加了以下代码

const AWS = require('aws-sdk');
async function sendTestNotification() {
    console.log("CALLED SEND TEST")
    const title = "Test Message"
    const message = "This is a message from Pinpoint dynamically delivered via code"
    const applicationId = <HARD CODED APPLICATION ID FROM PINPOINT CONSOLE>
    const token = <HARD CODED DEVICE TOKEN I USED IN THE TEST NOTIFICATION>
    var messageRequest = {
      'Addresses': {
        [token]: {
          'ChannelType' : 'APNS_SANDBox'
        }
      },'MessageConfiguration': {
        'APNSMessage': {
          'Action': 'OPEN_APP','Body': message,'Priority': 'normal','silentpush': false,'Title': title,'TimetoLive': 30
          }
      }
    };
    
    AWS.config.update({ region: 'us-east-1'});
    var pinpoint = new AWS.Pinpoint();

    var params = {
      "ApplicationId": applicationId,"MessageRequest": messageRequest
    }
    
    pinpoint.sendMessages(params,(sendMessagesErr,sendMessagesData) => console.log(sendMessagesErr,sendMessagesData))
}

exports.handler = async (event) => {
    console.log('running')    
    
    await sendTestNotification();
    const response = {
        statusCode: 200,body: JSON.stringify('Hello from Lambda!'),};
    return response;
};


当我测试该函数时,它正常运行并完成,没有错误。但是,没有通知通过。最初,我认为这可能与权限有关,但我已通过自定义角色授予 lambda 对 Pinpoint 的完全访问权限,但这仍然没有改变结果。

任何帮助将不胜感激,因为我不确定接下来要解决的问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)