【问题标题】:Safari Push Notificatin + permission "denied" and no log foundSafari 推送通知 + 权限“被拒绝”且未找到日志
【发布时间】:2016-02-22 08:16:52
【问题描述】:

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

我的客户文件位于... -public_html/push/index.html

服务器配置文件位于... -public_html/push/node_modules/express/index.js

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

我的 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>

它在“拒绝”警报之后给我们“默认”警报。 请帮帮我。

【问题讨论】:

    标签: javascript macos safari push-notification


    【解决方案1】:
    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 文件的同一位置有 tha aa.zip 文件的问题。有关更多信息,请检查您的节点日志,因为 console.log(req.body) 显示错误。

    【讨论】:

    • 不幸的是,情况不再如此;我的代码在:pizzomarinellafs.inarrivo.net/testSafari 总是返回被拒绝。这些回调都没有被调用: app.post('websockets.inarrivo.net/v2/pushPackages/…', function(req, res) { console.log('register'); res.sendfile('pushPackage.zip'); }); app.post('/v1/pushPackages/web.net.inarrivo.pizzomarinellafs', function(req, res) { console.log('Registering: Serving File'); res.sendFile('pushPackage.zip', { root : __dirname }); });
    猜你喜欢
    • 1970-01-01
    • 2011-12-24
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 2013-11-30
    • 2018-10-24
    • 2014-02-01
    相关资源
    最近更新 更多