Safari 推送通知(OS X Mavericks 和 Safari 7) [英] Safari push notification (OS X Mavericks and Safari 7)

查看:129
本文介绍了Safari 推送通知(OS X Mavericks 和 Safari 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了带有有效证书的推送包,并在带有有效 SSL 证书的服务器上托管,但问题是 javascript 总是在提示用户之前显示被拒绝的消息.我正在使用带有有效网站推送 id & 的苹果教程中的 java 脚本代码.网络服务网址等

I have created the push package with valid certificate and hosted on server with valid SSL certificate but problem is that javascript always shows the denied message even before prompting to user. I am using the java script code from apple tutorial with valid website push id & webservice url etc

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('web.com.example.domain');

        checkRemotePermission(permissionData);

    }

};


var checkRemotePermission = function (permissionData) {

    if (permissionData.permission === 'default') {

        // This is a new web service URL and its validity is unknown.

        window.safari.pushNotification.requestPermission(

            'https://domain.example.com', // The web service URL.

            'web.com.example.domain',     // The Website Push ID.

            {}, // 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.

    }

    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.

    }

};

问题是我在 javascript 中收到拒绝"警报,因为权限被拒绝.问题是它从来没有问过,也从来没有问过.它甚至不符合我的 Safari 偏好.

The problem is that I get 'denied' alert in my javascript , because the permission is denied. The thing is it never asked, nor has it ever asked before. Its not even in my safari preferences.

为什么 safari 不问就拒绝返回?

Why does safari return denied without even asking?

推荐答案

您需要定义以下服务器端端点

  1. webServiceURL/version/pushPackages/websitePushID——
    的位置推送包,由 POST 请求请求.

  1. webServiceURL/version/pushPackages/websitePushID – location of the
    push package, requested by POST request.

webServiceURL/version/devices/deviceToken/registrations/websitePushID– 当用户授予权限或稍后更新他的权限时
级别,发送 POST 请求.当用户删除权限时推送通知,发送 DELETE 请求.

webServiceURL/version/devices/deviceToken/registrations/websitePushID – when an user grants a permission or later updates his permission
level, a POST request is sent. When user removes the permission for push notifications, a DELETE request is sent.

webServiceURL/version/log – 当发生错误时,POST 请求是对这个端点进行

webServiceURL/version/log – when an error occurs a POST request is made to this endpoint

我建议你 fork 这个 github repo,它包括非常好的文档,可以使用 .htaccess 文件定义这些服务器端端点.

I suggest you to fork this github repo, It includes very good documentation and these server-side endpoints can be defined using .htaccess file.

这篇关于Safari 推送通知(OS X Mavericks 和 Safari 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆