safari push notification

86
Knowledge Sharing Session on Push Notification Service Global Blue Team February 2016

Upload: satyajit-dey

Post on 11-Feb-2017

525 views

Category:

Technology


9 download

TRANSCRIPT

Page 1: Safari Push Notification

Knowledge Sharing Session on Push Notification Service

Global Blue TeamFebruary 2016

Page 2: Safari Push Notification

Push Notification

Page 3: Safari Push Notification

Push Notification

• Notifies a user by messages or events• Originates from a server• The end user must opt-in to receive alerts

Page 4: Safari Push Notification

Why Push Notifications?

• Timely and relevant• Easy to access• Go straight to the details• Full control

Page 5: Safari Push Notification

Why Push Notifications?

• Timely and relevant

Page 6: Safari Push Notification

Why Push Notifications?• Easy to access

Page 7: Safari Push Notification

Why Push Notifications?

• Go straight to the details

Page 8: Safari Push Notification

Why Push Notifications?

• Full Control

Page 9: Safari Push Notification

Why Push Notifications?• Full Control

Page 10: Safari Push Notification

Safari Push Notification

Safari 7 along with OSX Mavericks

Page 11: Safari Push Notification

Safari Push Notification

Things we will learn-• Background• How it works• Implementation• Best practices

Page 12: Safari Push Notification

Safari Push Notification

Background

Page 13: Safari Push Notification

Safari Push Notification

• Local Web Notifications

Page 14: Safari Push Notification

Safari Push Notification

Local VS Push Notifications

Page 15: Safari Push Notification

Safari Push Notification

Local VS Push Notifications

Page 16: Safari Push Notification

Safari Push Notification

Apps VS Websites Push Notifications

Page 17: Safari Push Notification

Safari Push Notification

Apps VS Websites Push Notifications

Page 18: Safari Push Notification

Safari Push Notification

Page 19: Safari Push Notification

Safari Push Notification

Page 20: Safari Push Notification

Safari Push Notification

Page 21: Safari Push Notification

Safari Push Notification

Page 22: Safari Push Notification

Safari Push Notification

Page 23: Safari Push Notification

Safari Push Notification

Page 24: Safari Push Notification

Safari Push Notification

How it works

Page 25: Safari Push Notification

Safari Push Notification

Safari Push Notification works in two steps-1. Subscribing2. Delivering

Page 26: Safari Push Notification

Safari Push Notification

Subscribing

Page 27: Safari Push Notification

Safari Push Notification

Subscribing

Page 28: Safari Push Notification

Safari Push Notification

Subscribing

Page 29: Safari Push Notification

Safari Push Notification

Subscribing

Page 30: Safari Push Notification

Safari Push Notification

Subscribing

Page 31: Safari Push Notification

Safari Push Notification

Subscribing

Page 32: Safari Push Notification

Safari Push Notification

Subscribing

Page 33: Safari Push Notification

Safari Push Notification

Subscribing

Page 34: Safari Push Notification

Safari Push Notification

Subscribing

Page 35: Safari Push Notification

Safari Push Notification

Subscribing

Page 36: Safari Push Notification

Safari Push Notification

Delivering

Page 37: Safari Push Notification

Safari Push Notification

Delivering

Page 38: Safari Push Notification

Safari Push Notification

Delivering

Page 39: Safari Push Notification

Safari Push Notification

Delivering

Page 40: Safari Push Notification

Safari Push Notification

Delivering

Page 41: Safari Push Notification

Safari Push Notification

DEMO

Page 42: Safari Push Notification

Safari Push Notification

Implementation

Page 43: Safari Push Notification

Safari Push Notification

Implementation1. Get Website Push Certificate2. Implement Push Notification to your server

Page 44: Safari Push Notification

Safari Push Notification

Get Website Push Certificate1. Required to register in the Certificates, Identifiers & Profiles section of

the Member Center2. Registration requires an iOS developer license or Mac developer license.

Page 45: Safari Push Notification

Safari Push Notification

Page 46: Safari Push Notification

Safari Push NotificationWhen registering, include the following information: Identifier –

• Unique reverse-domain string, such as web.com.globalblue (the string must start with web).

• This is also known as the Website Push ID.

Website Push ID Description – • This is the name used throughout the Provisioning Portal to refer to your

website. • Use it for your own benefit to label your Website Push IDs into a more human-

readable format.

Page 47: Safari Push Notification

Safari Push Notification

• After providing the necessary informations the becomes available to download.

• Push Certificate must be coverted to .p12 format.

Page 48: Safari Push Notification

Safari Push Notification

Implement Push Notification to the server

Page 49: Safari Push Notification

Safari Push Notification

Implement Push Notification to the server• Ask On Your Website• Write Web Service Backend• Send Push Notifications

Page 50: Safari Push Notification

Safari Push Notification

Ask on Your Website: Query Permission

var result = window.safari.pushNotification.permission(websitePushID

);

Three types of permissions – result.permissions

1. "default"2. "denied"3. "granted"

Page 51: Safari Push Notification

Safari Push Notification

Ask on Your Website: Query Permission1. result.permissions == “default”– The user hasn’t yet been asked his or her permission.

2. result.permissions == “denied”– The user denied permission for the website to send

push notifications.3. result.permissions == “granted”– The user has allowed permission for the website to

send push notifications.

Page 52: Safari Push Notification

Safari Push Notification

Ask on Your Website: Query Permission

When permission is grantedresult.deviceToken = "96385da7....88aaebaf"

Page 53: Safari Push Notification

Safari Push Notification

Ask on Your Website: Request Permissionwindow.safari.pushNotification.requestPermission(

webServiceURL,websitePushID,userInfo,callback

);

Page 54: Safari Push Notification

Safari Push Notification

Ask on Your Website: Request PermissionwebServiceURL

– Base URL to your web service– Must be https

websitePushID– Unique identity of your website

userInfo– How your website passes information to your web service– Dictionary of strings

Page 55: Safari Push Notification

Safari Push Notification

Ask on Your Website: Request PermissionCallback

– When user confirmscallback({

permission: "granted",deviceToken: "96385da7....88aaebaf"

});

– When user deniescallback({

permission: "denied"});

Page 56: Safari Push Notification

Safari Push Notification

Write Web Service Back End

Page 57: Safari Push Notification

Safari Push Notification

Write Web Service Back End: Return push package• POST /v1/pushPackages/<websitePushID>• HTTP body is userInfo serialized as query string

window.safari.pushNotification.requestPermission(webServiceURL,websitePushID,userInfo,callback

);

Page 58: Safari Push Notification

Safari Push Notification

Write Web Service Back End: Return push package• POST /v1/pushPackages/<websitePushID>• HTTP body is userInfo serialized as query string

{“email": “[email protected]",“empId": “123456"

}

Page 59: Safari Push Notification

Safari Push Notification

Write Web Service Back End: Return push package• POST /v1/pushPackages/<websitePushID>• HTTP body is userInfo serialized as query string

{“email": “[email protected]",“empId": “123456"

}

• Serialized Info: [email protected]&empId=123456

Page 60: Safari Push Notification

Safari Push NotificationWrite Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Page 61: Safari Push Notification

Safari Push NotificationWrite Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Icons – • Used in notifications• Notification Center• Safari Browser• System Preferences

Page 62: Safari Push Notification

Safari Push Notification

• Defines website• Checked during validation• Used in notifications and • Notification Centre

Write Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Page 63: Safari Push Notification

Safari Push Notification

{ "webServiceURL": "https://globalblue.com/ws", "websitePushID": "web.com.globalblue", "websiteName": "Global Blue", "allowedDomains": ["http://globalblue.com"], "authenticationToken": "1e3f7d98ac417df", "urlFormatString": "http://globalblue.com/%@?articleId=%@"}

Write Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Page 64: Safari Push Notification

Safari Push Notification

JSON dictionary of SHA1 checksums

Write Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Page 65: Safari Push Notification

Safari Push Notification

{ "icon.iconset\/icon_16x16.png": "865f...17e1", "icon.iconset\/[email protected]": "1a47...35ca", "icon.iconset\/icon_32x32.png": "aa75...fbb6", "icon.iconset\/[email protected]": "88e8...351d", "icon.iconset\/icon_128x128.png": "0509...6228", "icon.iconset\/[email protected]": "e956...6611", "website.json": "9683...b3a8"}

Write Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Page 66: Safari Push Notification

Safari Push NotificationWrite Web Service Back End

Push Package DIR Structure:GlobalBlue.pushpackage/

icon.iconset/[email protected][email protected][email protected]

website.jsonmanifest.jsonsignature

Signature of manifest.json

Page 67: Safari Push Notification

Safari Push Notification

Write Web Service Back EndLogging errors• POST /v1/log• HTTP Body{"logs": ["Referrer URL http://globalblue.com/ is not in the list of allowed domains."]}

Page 68: Safari Push Notification

Safari Push Notification

Push Notification Dialog

Push Package

Icons

websiteName

Page 69: Safari Push Notification

Safari Push Notification

Write Web Service Back EndRegister user’s device token• POST

/v1/devices/<deviceToken>/registrations/<websitePushID>

• HTTP Authorize header fieldApplePushNotifications <authenticationToken>

Page 70: Safari Push Notification

Safari Push Notification

Write Web Service Back EndUnregister user’s device token• DELETE

/v1/devices/<deviceToken>/registrations/<websitePushID>

• HTTP Authorize header fieldApplePushNotifications <authenticationToken>

Page 71: Safari Push Notification

Safari Push Notification

Send Push Notifications

Page 72: Safari Push Notification

Safari Push Notification

Send Push Notifications

Page 73: Safari Push Notification

Safari Push Notification

Provider-to-APNs Connection Trust

Page 74: Safari Push Notification

Safari Push Notification

APNs-to-Device Connection Trust

Page 75: Safari Push Notification

Safari Push Notification

Device Token Generation

Page 76: Safari Push Notification

Safari Push Notification

Send Push NotificationsPush Payload{

"aps": {"alert": {

"title": “Nike Milan","body": “50% off for all Nike products.","action": "View"

},"url-args": [“milan", “532401"]

}}

Page 77: Safari Push Notification

Safari Push Notification

Send Push NotificationsPush Payload{

"aps": {"alert": {

"title": “Nike Milan","body": “50% off for all Nike products.","action": "View"

},"url-args": [“milan", “532401"]

}}

Page 78: Safari Push Notification

Safari Push Notification

Send Push NotificationsPush Payload{

"aps": {"alert": {

"title": “Nike Milan","body": “50% off for all Nike products.","action": "View"

},"url-args": [“milan", “532401"]

}}

Page 79: Safari Push Notification

Safari Push Notification

Send Push NotificationsPush Payload{

"aps": {"alert": {

"title": “Nike Milan","body": “50% off for all Nike products.","action": "View"

},"url-args": [“milan", “532401"]

}}

• Maximum size for message payload is 256 bytes.• Always connect to Production Environment

Page 80: Safari Push Notification

Safari Push Notification

Push Notifications and Notification Center

Push Package

Icons

websiteName

urlFormatString

NotificationPayload

title

action

body

url-args

Page 81: Safari Push Notification

Safari Push Notification

Push Notifications and Notification Center

Push Package

Icons

websiteName

urlFormatString

NotificationPayload

title

action

body

url-args

Page 82: Safari Push Notification

Safari Push NotificationPush Notifications and Notification Centerhttp://globalblue.com/%@?articleId=%@ [“milan", " 532401 "]

Push Package

Icons

websiteName

urlFormatString

NotificationPayload

title

action

body

url-args

Page 83: Safari Push Notification

Safari Push NotificationPush Notifications and Notification Center

http://globalblue.com/milan?articleId=532401

Push Package

Icons

websiteName

urlFormatString

NotificationPayload

title

action

body

url-args

Page 84: Safari Push Notification

Safari Push Notification

Best Practice• Think about what notifications are most useful• Use notifications as an additional, not primary means of communication• Take advantage of the URL format string

• Strip whitespace from your JSON payload• You can use URL shortener to keep the payload size in limit.

Push Package urlFormatString: http://%@Website.json

Payloadurl-args: ["globalblue.com/brands/specials/boggi/boggi-milan/"]

Page 85: Safari Push Notification

Safari Push Notification

Questions?

Page 86: Safari Push Notification

Safari Push Notification

Thank You