【问题标题】:How to create voip push notification from Node.js server如何从 Node.js 服务器创建 voip 推送通知
【发布时间】:2021-07-28 16:07:49
【问题描述】:

我想在我的 iOS 应用程序不活动时向它发送 voip 推送,我尝试使用来自 this solutionapn module 但它对我不起作用。 我关注了关于 voip push here 的官方苹果文档,但从服务器发送它仍然存在一些问题。 我也尝试通过 AWS sns 服务发送它,但得到了正常推送通知等。

我做错了什么?

现在我的代码是:

这里我为 sns 项目做格式化

const formatVoipPushNotificationsToSend = (type, header, launchId, sender, to = '', device_token, token) => {
    
    const headers = {
        ':method': 'POST',
        'apns-topic': '************.voip', //application bundle ID
        ':scheme': 'https',
        ':path': `/3/device/${device_token}`,
        'authorization': `bearer ${token}`,
        'apns-push-type': 'voip',
    };

    const aps = {
        alert: {
            title: header,
            body: 'text' || null
        },
        itemId: type,
        from: sender || null,
        to,
        launchId: launchId || null,
        'content-available': 1
    };
    return { aps, headers };
};

然后我在这里传递项目并将其发送到带有 sns 端点的应用程序。

const pushNotifications = (item, arn, userId) => {
    const payload = JSON.stringify(item);

    const snsMessage = {};
    snsMessage[SNS_PAYLOAD_KEY] = payload;

    const params = {
        Message: JSON.stringify(snsMessage),
        TargetArn: arn,
        MessageStructure: 'json'
    };

    const eventBody = item.aps.itemId ? {
        [EVENT_TYPES.PUSH_SEND]: item.aps.itemId
    } : {};
    
    AmplitudeService.logEvent(EVENT_TYPES.PUSH_SEND, userId, eventBody);

    return snsClient.publish(params).promise();
};

【问题讨论】:

    标签: ios node.js amazon-web-services apple-push-notifications voip


    【解决方案1】:

    我使用的是稍微不同的方法:

    var apn = require('apn');
    const { v4: uuidv4 } = require('uuid');
    
    const options = {
      token: {
        key: 'APNKey.p8',
        keyId: 'S83SFJIE38',
        teamId: 'JF982KSD6f'
      },
      production: false
    };
    var apnProvider = new apn.Provider(options);
    
    // Sending the voip notification
    let notification = new apn.Notification();
    
    notification.body = "Hello there!";
    notification.topic = "com.myapp.voip";
    notification.payload = {
      "aps": { "content-available": 1 },
      "handle": "1111111",
      "callerName": "Richard Feynman",
      "uuid": uuidv4()
    };
    
    apnProvider.send(notification, deviceToken).then((response) => {
      console.log(response);
    });
    

    【讨论】:

    • 您是在项目文件夹中保留 APNKey.p8 文件还是只传递它的名称? @egor518
    • 还有一个问题 - 您是直接从服务器发送它还是使用 firebase 或 aws?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多