No commit activity in last 3 years
No release in over 3 years
Apple Web Push Notifications Package Generator
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
> 2.0

Runtime

>= 0
>= 3.1.0
< 1.0.0
 Project Readme

Apple Safari Web Push Notification Gem for Rails

Apple Web Push Notifications

Overview

Checkout the Apple WWDC Session Video before if you want an overview on how the Safari push notifications work.

Usage

Install

gem 'web-push-notification-rails'
bundle install

P12 certificate

This the first of 2 certificates you need to sign. Apple has a step-by-step for most of it. You can pick up from step 7. Alternatively, you can follow all of my steps:

  1. Go to iOS Provisioning Portal (you need to login or register)
  • Click on "Website Push IDs" on the left side menu
  • Click on "New Website Push ID" and fill in the 2 fields
  • After you come back to the listing of website push ids, select the created Push Id and click on "Edit" and then "Create Certificate..."
  • Follow the steps on About Creating a Certificate Signing Request (CSR)
  • Once you download the Certficate.cer, double-click to install
  • In the "Keychain Access" tool right-click on Website Push ID: <web.company.id> and select both and right click "Export 2 items...
  • Change "File Format" to "Personal Information Exchange(.p12)" and save (preferably to Rails.root/cert/)
  • The password you enter during the saving process will go into the initializer ("Run Generator" step)

WWDR Certificate

Second certificate you need to sign the web package

  1. Download http://developer.apple.com/certificationauthority/AppleWWDRCA.cer
  • Double-click to install
  • In the "Keychain Access" tool right-click on "Apple Worldwide Developer Relations Certification Authority" and click on Export "Apple....
  • Change "File Format" to "Privacy Enhanced Mail (.pem)" and save it (preferably to Rails.root/cert/)

Run generators

Last password parameter is optional. You can just edit the initializer later

   rails g web_notification:notification_package website_name website_service_url website_push_id website_allowed_domain website_url_formatted_string wwdr_certificate_path key_path [cert_password]

Example:

   rails g web_notification:notification_package mixtapp https://www.mixtapp.co web.com.encoredevlabs.mixtapp https://www.mixtapp.co "https://www.mixtapp.co?%@" cert/AppleWWDRCA.cer cert/website_aps_production.cer.p12 password

If password is blank do not enter the last parameter: cert_password and a blank password will be used.

Customize

If you need to change the password or location of the certificates later you can change it in the web_notification_package_initializer.rb file.

The package sent to Apple is inside notfication/web_package folder in Rails.root. Customize the icons inside icon.iconset folder. You can also customize the website.json which was genereated using the values specified in the generator. Checkout the Apple documentation link to see what values you need to set in the json file.

Apple Callback to Controller

All request from Apple regarding the web package will be sent to apple_web_notifications_controller.rb which you can customize or you can change the generated routes in the routes.rb file and send the Apple callback methods to your desired controller.

You will need to implement what needs to be done once you get the device token from Apple.

Features to be implemented

Ability to send Push Notification from the rails server as currently I am testing by sending notification using the Houston like this

  apn push "64BE8308E51B6B91C0D41A8C856274977A6A45650049435C02F5E9944AB9D7F7" -c cert/apple_push_notification.pem -e production -P "{\"aps\":{\"alert\":{\"title\":\"Title test\",\"body\":\"Body test\"},\"url-args\":[\"someparams\"]}}"

If you have any questions or need help, find me on Twitter: @ankurpatel

Bitdeli Badge