Safari Push Notificatin + permission"拒绝"并且没有找到日志

时间:2016-02-22 08:16:52

标签: javascript macos safari push-notification

我尝试整合safari推送通知。我提到以下链接。 http://samuli.hakoniemi.net/how-to-implement-safari-push-notifications-on-your-website/#resources

我的客户端文件是... -public_html /推/ index.html中

服务器配置文件位于...... -public_html /推/ node_modules /快递/ index.js

推送包和日志文件是... -public_html / push / v1 / pushPackages / [my push id] /myPackage.zip -public_html / push / v1 / pushPackages / [我的推送ID] /日志(文件)

我的index.js文件包含以下代码。

'use strict';

module.exports = require('./lib/express');

//Test code for Safari push notification
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;


app.listen(port);

app.get('/', function(req, res) {
    res.sendfile('index.html');
});

app.post('/v1/pushPackages/[my push id]', function(req, res) {
alert('hello');
    res.sendfile('myPushPackage.zip');
});

app.post('/v1/log', function(req, res) {
});

我的客户端文件(index.html)包含以下代码:

!doctype html>
<html>
    <head>
        <title> Safari Push Notifications</title>
    </head>
    <body>
        <h1>Safari Push Notifications</h1>
        <a href="#" id="subscribe">Subscribe</a>
        <script>


var pushId = [my push id];
document.body.onload = function() {
    // Ensure that the user can receive Safari Push Notifications.
    if ('safari' in window && 'pushNotification' in window.safari) {
        var permissionData = window.safari.pushNotification.permission(pushId);
        checkRemotePermission(permissionData);

    } else {
        alert("Push notifications not supported.");
    }
};

var checkRemotePermission = function (permissionData) {

    if (permissionData.permission === 'default') {
     alert("default.");
        // This is a new web service URL and its validity is unknown.
        console.log("The user is making a decision");
//alert('The user is making a decision');
        var userinfo={};
  window.safari.pushNotification.requestPermission(
            'https://[mydomain]/push', // The web service URL.
            pushId,     // The Website Push ID.
            userinfo, // Data that you choose to send to your server to help you identify the user.
            checkRemotePermission         // The callback function.
        );
    }
    else if (permissionData.permission === 'denied') {
     alert("denied.");
        // The user said no.
        console.log('denied');
    }
    else if (permissionData.permission === 'granted') {
     alert("granted.");
        // The web service URL is a valid push provider, and the user said yes.
        // permissionData.deviceToken is now available to use.
        console.log("The user said yes, with token: "+ permissionData.deviceToken);
    }
};
        </script>
    </body>
</html>

它给我们提醒&#34;默认&#34;之后&#34;否认&#34;警报。 请帮帮我。

1 个答案:

答案 0 :(得分:0)

app.post('/v1/pushPackages/[pushid]', function(req, res) {  
    console.log('Serving File');    
    res.sendFile('aa.zip', { root: __dirname });
});

app.post('/v1/log', function(req, res) {  
         console.log('Received LOG');
         console.log(req.body);
});

这解决了我在index.js文件的同一位置上有aa.zip文件的问题。有关更多信息,请检查节点日志,因为console.log(req.body)显示错误。