Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Created August 4, 2015 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunojppb/2206fa70c786583d09bc to your computer and use it in GitHub Desktop.
Save brunojppb/2206fa70c786583d09bc to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
def create
post = Post.new(post_params)
# Get all devices stored on your database
# or filter based on your criteria
devices = Device.all
notifications = devices.map do |d|
APNS::Notification.new(d.token,
alert: post.title,
other: 'Here, you can pass custom info to your app')
end
APNS.send_notifications(notifications) if !notifications.empty?
end
protected
def post_params
params.require(:post).permit(:title, :content)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment