On Github pivotalsquid / simple-push-notifications
i wanted to be able to send a notififcation to my phone from a curl command, perhaps at the end of a long running script,
i wanted to learn a little about swift
curl -X POST -H "Content-Type: application/json" -d '{"msg": "Ping!"}' "http://localhost:3000/ping"
simple endpoint to accept the curl request and create a job
class PingController < ApplicationController def create PingJob.perform_later(params['msg']) respond_to do |format| format.json { head :ok } end end end
require 'houston' class PingJob < ActiveJob::Base queue_as :pingme def perform(*args) apn = Houston::Client.development apn.certificate = File.read('config/certs/cert_and_key.pem') apn.passphrase = 'password!' device_token = '<6d67435d de8dbaea 10f6d693 ..... e7183199>' notification = Houston::Notification.new(device: device_token) notification.alert = args[0] notification.sound = 'sosumi.aiff' apn.push(notification) end end
create a single view app that does almost nothing
didFinishLaunchingWithOptions
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) UIApplication.sharedApplication().registerUserNotificationSettings(settings) UIApplication.sharedApplication().registerForRemoteNotifications() return true }
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { print("Got token data! \(deviceToken)") }
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { print("Couldn't register: \(error)") }
objective-c examples are everywhere
swift, nowhere to be found
creating app id
apn ssl certificate
convoluted mess converting .p12 to pem, etc
can only be done on the sending side
nothing available on the apple side
verify error:num=20:unable to get local issuer certificate
certificate authority files are your friends
as simple as this seemed, there are a lot of pieces
configuring the certs properly is a pain