Safari push notifications return denied without asking

戏子无情 提交于 2019-11-30 22:15:44

This error can happen when testing locally because the address you are testing from isn't part of the allowedDomains array in the site's pushPackage. For https://zeropush.com, we added the host lvh.me to our pushPackage and ran the server on port 80, while we were implementing safari push notifications. You then access your development site at lvh.me and things should behave normally.

You should also implement the logging endpoint for your site described in the safari push notification docs so that you can get any error log information to help you in debugging.

I also wrote a post about implementing safari push notifications that is somewhat ruby centric, but may be of use. https://zeropush.com/blog/implementing-safari-push-notifications-in-osx-mavericks.

It seems that this behavior can occur when testing "locally" on your machine with a "self-signed" SSL certificate.

I was seeing this exact same behavior while attempting to get Safari Push Notifications working in a Rails 4 app locally on my machine. I was using nginx with a self-signed SSL certificate generated on the command line.

I was using javascript code very similar to yours, and I'd constantly see a "denied" output form my debug console.log statements, yet no prompt was ever displayed to the user requesting their permission to send them push notifications.

After one such attempt, I checked Console.app on my machine. It was then that I found this little cryptic, yet seemingly related/helpful nugget of info:

SafariNotificationAgent[65893]: NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9812)

This, coupled with a few responses with similar guesses from the official Apple Developer Forums, leads me to believe that the self-signed SSL certificate is the culprit in this case.

I'd love to hear anyone else's ideas on a better way to go about testing Safari Push Notifications locally.

I got the same problem when testing Notifications locally! But I found a solution: if you copy the file to your Sites folder in your home folder and access it via the included apache (e.g.: http://localhost/~username/notification.html) it will ask you for permissions and work as expected :)

Initially, the permission is set to default due to which, safari makes a post call to download the pushPackage to your webserviceURL. Safari would return denied even if your pushPackage is invalid in any way. Refer to the flowchart given here and also the error logs

https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html

You would also need a valid SSL Certificate(not self signed) as already mentioned. Best Practice would be to implement /version/log to diagnose the errors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!