簡體   English   中英

如何從 Node.js 服務器創建 voip 推送通知

[英]How to create voip push notification from Node.js server

我想在不活動時將 voip push 發送到我的 iOS 應用程序,我嘗試使用此解決方案中的apn module ,但它對我不起作用。 在這里關注了關於 voip push 的官方蘋果文檔,但是從服務器發送它仍然存在一些問題。 我還嘗試通過 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();
};

我使用了一種稍微不同的方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM