Created
August 4, 2015 16:55
-
-
Save brunojppb/2206fa70c786583d09bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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