【问题标题】:Backend service for ionic push离子推送的后端服务
【发布时间】:2016-04-20 12:48:57
【问题描述】:

我已经使用 pushwoosh 实现了离子推送通知。但是在那里我使用 pushwoosh 提供的仪表板来发送推送通知。我想使用我自己创建的后端发送推送通知。我该怎么做?

【问题讨论】:

    标签: ionic-framework backend pushwoosh


    【解决方案1】:

    我正在研究离子框架,并且还使用推送通知通过 REST API 使用node-gcm 发送通知@ 其工作正常。 示例代码

    (function() {
    function execute(rqst, q, fwk) {
        var gcm = require('node-gcm');
    
        var message = new gcm.Message();
        message.timeToLive = 3000;
        message.addData({
            title: 'Push Notification Sample',
            body: 'Abnormal data access',
            icon: 'ic_launcher',
            message: '"\u270C Peace, Love \u2764 and PhoneGap \u2706!'
        });
        message.addNotification({
            title: 'Push Notification Sample',
            body: 'Abnormal data access',
            icon: 'ic_launcher',
            message: 'hey , how are you?'
        });
    
    
        /* message.addData('message', "\u270C Peace, Love \u2764 and PhoneGap \u2706!");
    
         message.addData('title', 'Push Notification Sample');
    
         message.addData('msgcnt', '3');*/
        // Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
    
        // Set up the sender with you API key
        var sender = new gcm.Sender('xxxxxxxxxxxxxxxxx-hK5wE');
    
        // Add the registration IDs of the devices you want to send to
    
        var registrationIds = [];
        registrationIds.push('APA91bEWB6-xcrfrfrffr-LqyMohLP4T-XuydQgt44Q6Acw5kmVDWvAaOsm1CriASm02SyBceZ2NBWF4FIES7grcPeY5v4fLQme2UqhRteeWRdD_Ma25QMGESOGAyw_Uhgg_EjkTl-');
    
    
        // Send the message
        // ... trying only once sendNoRetry
    
        sender.send(message, {
            registrationIds: registrationIds
        }, function(err, result) {
            if (err) {
                console.error(err);
                q.resolve({
                    status: 200,
                    data: {
                        data: err,
                        code: 1
                    }
                });
            } else {
                console.log(result);
                q.resolve({
                    status: 200,
                    data: result
                });
            }
        });
    
    }
    return exports.execute = execute;
    })();
    

    【讨论】:

    • 我是推送通知的新手。那么,您是从您的 REST API 启动此 javascript 代码吗?如果用户不启动应用程序,他们将如何获得此推送通知?您能解释一下如何从 REST Svc 发送这些推送通知吗?这也是我需要做的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    相关资源
    最近更新 更多