Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

so i started to play with Safari Push notifications, here is my experience:

Setup

like iOS, you need to login to the dev portal and create an application ID, in this case a website ID, then do all the same things with certifcates and such.

the next part is you need to create a "push package" that either resides on the server your "website/webapp" is on as a .zip, or created dynamically at runtime. more on this later

The push package contains some things that are ultimately signed with your create certificate.

here is a link for more detail on the push package pp link

The client and server

Safari 7 on Mavericks ships with some new API's for doing push.

the first:

window.safari.pushNotification.requestPermission(url, websitePushID, userInfo, callback);

*url - a https url to a webservice *websitePushID - website push ID created in the dev console *userInfo - just some metadata if you want *callback - yup, it's asynchronous

so when this call is made, safari will make a POST to an endpoint like this:

webServiceURL/version/pushPackages/websitePushID

this is where you would serve your push package with the application/zip content type header thing

if all goes well with the push package, safari will ask the user to allow notifications, if the user allows them, then a POST to this endpoint happens

webServiceURL/version/devices/deviceToken/registrations/websitePushID

and the "device token" is then returned in the callback from above

a DELETE sent to that same endpoint if a user removes permissions.( haven't tried this yet )

if any error happens during any of these calls, this endpoint is POST'ed to

webServiceURL/version/log

here is my repo that is running on openshift( the easist way to get https since safari doesn't like self signed certs )

https://github.com/lholmquist/safaripush

the hardest part of this whole things is the actual setup of the push package

here is a repo i found that helped a bit, and apple also has a file that tries to help

https://github.com/connorlacombe/Safari-Push-Notifications

yes, i know, php.

i'm in the process of writing a node version, and yes, i've seen this one https://npmjs.org/package/web-push-package

UPS

So the good news is that the developer has to do all that stuff before they interact with the UPS.

Safari uses APNs( production only gateway ), but the payload is slightly different.

{
    "aps": {
        "alert": {
            "title": "Flight A998 Now Boarding",
            "body": "Boarding has begun for Flight A998.",
            "action": "View"
        },
        "url-args": ["boarding", "A998"]
    }
}

title and body are required

i sent a PR to get this updated in the java_apns thing notnoop/java-apns#135

so we'll see what happens there

there is a lot of duplication in the UPS for the APN's stuff, i just wanted to get things to work first, but iOS and Safari share almost everything.

So maybe we need a more general APNs variant/sender whatever. i'm javascript dude, so my java skills are a bit rusty

i have a branch of the UPS where i am playing with this here https://github.com/lholmquist/aerogear-unified-push-server/tree/safaripush

the update UI is here https://github.com/lholmquist/aerogear-unified-push-server-admin-ui/tree/safarpush

the modified java_apns is here

https://github.com/lholmquist/java-apns/tree/safari_push

there might be things missing, i'm just trying to download my brain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment