Giter Site home page Giter Site logo

prx / apn_on_rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jwang/apn_on_rails

540.0 24.0 159.0 328 KB

Apple Push Notifications on Rails

Home Page: http://rubydoc.info/github/PRX/apn_on_rails/master/frames

License: MIT License

Ruby 100.00%

apn_on_rails's Introduction

APN on Rails (Apple Push Notifications on Rails)

APN on Rails is a Ruby on Rails gem that allows you to easily add Apple Push Notification (iPhone)
support to your Rails application.

It supports:

  • Multiple iPhone apps managed from the same Rails application as well as a legacy default “app” with certs stored in config
  • Individual notifications and group notifications
  • Alerts, badges, sounds, and custom properties in notifications
  • Pull notifications

Feature Descriptions

Multiple iPhone Apps: In previous versions of this gem a single Rails application was set up to
manage push notifications for a single iPhone app. In many cases it is useful to have a single Rails
app manage push notifications for multiple iPhone apps. With the addition of an APN::App model, this
is now possible. The certificates are now stored on instances of APN::App and all devices are intended to be associated
with a particular app. For compatibility with existing implementations it is still possible to create devices that
are not associated with an APN::App and to send individual notifications to them using the certs stored in the
config directory.

Individual and Group Notifications: Previous versions of this gem treated each notification individually
and did not provide a built-in way to send a broadcast notification to a group of devices. Group notifications
are now built into the gem. A group notification is associated with a group of devices and shares its
contents across the entire group of devices. (Group notifications are only available for groups of devices associated
with an APN::App)

Notification Content Areas: Notifications may contain alerts, badges, sounds, and custom properties.

Pull Notifications: This version of the gem supports an alternative notification method that relies
on pulls from client devices and does not interact with the Apple Push Notification servers. This feature
may be used entirely independently of the push notification features. Pull notifications may be
created for an app. A client app can query for the most recent pull notification available since a
given date to retrieve any notifications waiting for it.

Version 0.4.1 Notes

  • Backwards compatibility. 0.4.0 required a manual upgrade to associate existing and new devices with an APN::App model. This version allows continued use of devices that are associated with a default “app” that stores its certificates in the config directory. This ought to allow upgrade to this version without code changes.
  • Batched finds. Finds on the APN::Device model that can return large numbers of records have been batched to limit memory impact.
  • Custom properties migration. At a pre-0.4.0 version the custom_properties attribute was added to the migration template that created the notifications table. This introduced a potential problem for gem users who had previously run this migration. The custom_properties alteration to the apn_notifications table has been moved to its own migration and should work regardless of whether your apn_notifications table already has a custom_properties attribute.
  • last_registered_at changed to work intuitively. The last_registered_at attribute of devices was being updated only on creation potentially causing a bug in which a device that opts out of APNs and then opts back in before apn_on_rails received feedback about it might miss a period of APNs that it should receive.

Acknowledgements:

From Mark Bates:

This gem is a re-write of a plugin that was written by Fabien Penso and Sam Soffes.
Their plugin was a great start, but it just didn’t quite reach the level I hoped it would.
I’ve re-written, as a gem, added a ton of tests, and I would like to think that I made it
a little nicer and easier to use.

From Rebecca Nesson (PRX.org):

This gem extends the original version that Mark Bates adapted. His gem did the hard
work of setting up and handling all communication with the Apple push notification servers.

Converting Your Certificate:

Once you have the certificate from Apple for your application, export your key
and the apple certificate as p12 files. Here is a quick walkthrough on how to do this:

1. Click the disclosure arrow next to your certificate in Keychain Access and select the certificate and the key.
2. Right click and choose `Export 2 items…`.
3. Choose the p12 format from the drop down and name it `cert.p12`.

Now covert the p12 file to a pem file:


  $ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts

If you are using a development certificate, then change the name to apple_push_notification_development.pem instead.

Store the contents of the certificate files on the app model for the app you want to send notifications to.

Installing:

Stable (RubyForge):


  $ sudo gem install apn_on_rails

Edge (GitHub):


  $ sudo gem install PRX-apn_on_rails.git --source=http://gems.github.com

Rails Gem Management:

If you like to use the built in Rails gem management:


  config.gem 'apn_on_rails'

Or, if you like to live on the edge:


  config.gem 'PRX-apn_on_rails', :lib => 'apn_on_rails', :source => 'http://gems.github.com'

Setup and Configuration:

Once you have the gem installed via your favorite gem installation, you need to require it so you can
start to use it:

Add the following require, wherever it makes sense to you:


  require 'apn_on_rails'

You also need to add the following to your Rakefile so you can use the
Rake tasks that ship with APN on Rails:


  begin
    require 'apn_on_rails_tasks'
  rescue MissingSourceFile => e
    puts e.message
  end

You now need to run the APN generator to create the migration files.


ruby script/rails generate apn_on_rails:install

Now, to create the tables you need for APN on Rails, run the following task:


  $  rake db:migrate

APN on Rails uses the Configatron gem, http://github.com/markbates/configatron/tree/master,
to configure itself. With the change to multi-app support, the certifications are stored in the
database rather than in the config directory.

However, it is still possible to use the default “app” and the certificates
stored in the config directory. For this setup, the following configurations apply.)
APN on Rails has the following default configurations that you change for your setup.

To generate the files that will be used here, run


script/rails generate configatron:install

Then customize the config/configatron files that were generated to your settings.


  # development (delivery):
  configatron.apn.passphrase # => ''
  configatron.apn.port # => 2195
  configatron.apn.host # => 'gateway.sandbox.push.apple.com'
  configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')
  
  # production (delivery):
  configatron.apn.host # => 'gateway.push.apple.com'
  configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_production.pem')
  
  # development (feedback):
  configatron.apn.feedback.passphrase # => ''
  configatron.apn.feedback.port # => 2196
  configatron.apn.feedback.host # => 'feedback.sandbox.push.apple.com'
  configatron.apn.feedback.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')
  
  # production (feedback):
  configatron.apn.feedback.host # => 'feedback.push.apple.com'
  configatron.apn.feedback.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_production.pem')

That’s it, now you’re ready to start creating notifications.

Upgrade Notes:

If you are upgrading to a new version of APN on Rails you should always run:


ruby script/rails generate apn_on_rails:install

That way you ensure you have the latest version of the database tables needed.
(There is an unaddressed problem in which migration 002 was modified in the repo to add the column custom_properties.
If you installed the gem prior to that change and try to upgrade following this path you will have to add the
custom_properties column to the apn_notifications table by hand.)

Example (assuming you have created an app and stored your keys on it):


  $ ./script/console
  >> app = APN::App.create(:apn_dev_cert => "PASTE YOUR DEV CERT HERE", :apn_prod_cert => "PASTE YOUR PROD CERT HERE")
  >> device = APN::Device.create(:token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX",:app_id => app.id)
  >> notification = APN::Notification.new
  >> notification.device = device
  >> notification.badge = 5
  >> notification.sound = true
  >> notification.alert = "foobar"
  >> notification.custom_properties = {:link => "http://www.prx.org"}
  >> notification.save

You can use the following Rake task to deliver your individual notifications:


  $ rake apn:notifications:deliver

And the following task to deliver your group notifications:


  $ rake apn:group_notifications:deliver

The Rake task will find any unsent notifications in the database. If there aren’t any notifications
it will simply do nothing. If there are notifications waiting to be delivered it will open a single connection
to Apple and push all the notifications through that one connection. Apple does not like people opening/closing
connections constantly, so it’s pretty important that you are careful about batching up your notifications so
Apple doesn’t shut you down.

Released under the MIT license.

apn_on_rails's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apn_on_rails's Issues

No name attribute in APN:App

I may be missing something, but I don't see a 'name' attribute in APN:App, yet it appears in the example of the readme. Some sort of app identifier, whether it be the bundle name, or the bundle id would be useful.

APN::App.send_notifications results in high DB load

Hello

we recently switched from wireframe apn_on_rails to PRX apn_on_rails (0.4.1), and we noticed a significant increase in DB load. It seems that this is due to a nested loop in the function send_notifications_for_cert (in the app model), which creates a DB query for each device, whereas the wireframe version uses a simple APN::Notification.all(:conditions => {:sent_at => nil}) to find all notifications to send.

I understand the benefit of being able to specify an app_id per device, but I think it should still be possible to just use one query to get all notifications to send, which would be significantly faster.

Sound off

Notification sound set with: notification.sound=false is not working for me, the notification still have sound. Can you confirm this is a bug?

Remove/Change puts log message

/app/models/apn/app.rb:134 puts "in APN::App.process_devices_for_cert"

Can that be removed? It's just filling the log file with a relatively useless message.

Triggering APN on New Message

I'm curious, and I just may not be seeing it in the explanation, of where I would put the trigger to send the APN when a new Message is received. Just as a brief explanation, I want to send a push notification to a user when he receives a new message. Can anyone provide me with some assistance on how to make this work?

undefined method `log_connection_exception'

using 0.4.2 gem

try to deliver a notification to apple, but failed, with this error:

undefined method log_connection_exception' for #<Class:0x6cfbee8> c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1994 :inmethod_missing_without_paginate'
C:/Users/Leonardo Wong/workspace/projectA/vendor/plugins/will_paginate/lib/will_
paginate/finder.rb:170:in method_missing' c:/ruby/lib/ruby/gems/1.8/gems/apn_on_rails-0.4.2/lib/apn_on_rails/app/models/ap n/app.rb:58:insend_notifications_for_cert'
c:/ruby/lib/ruby/gems/1.8/gems/apn_on_rails-0.4.2/lib/apn_on_rails/app/models/ap
n/app.rb:26:in send_notifications' c:/ruby/lib/ruby/gems/1.8/gems/apn_on_rails-0.4.2/lib/apn_on_rails/app/models/ap n/app.rb:32:insend_notifications'
c:/ruby/lib/ruby/gems/1.8/gems/apn_on_rails-0.4.2/lib/apn_on_rails/app/models/ap
n/app.rb:31:in each' c:/ruby/lib/ruby/gems/1.8/gems/apn_on_rails-0.4.2/lib/apn_on_rails/app/models/ap n/app.rb:31:insend_notifications'
c:/ruby/lib/ruby/gems/1.8/gems/apn_on_rails-0.4.2/lib/apn_on_rails/tasks/apn.rak
e:7
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in call' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:inexecute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in each' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:inexecute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in invoke_with_call_c hain' c:/ruby/lib/ruby/1.8/monitor.rb:242:insynchronize'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_c hain' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:ininvoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in each' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exceptio n_handling' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:intop_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exceptio
n_handling'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 c:/ruby/bin/rake:19:inload'
c:/ruby/bin/rake:19

In app.rb, i comment line 58, and put "puts e.message" there, it shows:
259 out of char range

I know my message(alert) is too long, I will fix that, just try to report the code error here.

Thanks for this nice plugin. Save me a lot of time.

applications based on different Rails.env couldn't be recognised

code segment in lib/apn_on_rails/app/models/apn/app.rb
def cert
   (Rails.env == 'production' ? apn_prod_cert : apn_dev_cert)
 end

could it be changed to
def cert
   (Rails.env=='development' ? apn_dev_cert : apn_prod_cert)
 end

our projects are based on different Rails.env, and I need to use both apn_notification and apn_group_notification, so I couldn't use configatron(it doesn't support group notification)

please help me, THANKS!

Is an app required?

The old version of apn_on_rails had no concept of apps. It was assumed you only had one set of certificates.

This new (and improved!) version lets you group devices by app; however, it's not clear if it's required.

If you only have one app, do you still need to define that app in the databse, or can you use apn_on_rails in a way backwards compatible with markbates' version?

M

Certificate issues which aren't found on other libraries

Hi,

Suddenly one of my apps that uses apn_on_rails stopped sending notifications.

APN::App.send_notifications fails with:

SSL_connect returned=1 errno=0 state=SSLv3 read server session ticket A: sslv3 alert certificate expired
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server session ticket A: sslv3 alert certificate expired
      from ~/.rbenv/versions/ree-1.8.7-2011.03/gems/apn_on_rails-0.5.1/lib/apn_on_rails/libs/connection.rb:59:in `connect'

The cert is valid until 2013, and it works fine if I use something like node-apn. I don't see anything obvious in the source code and I know little of SSL, so I'm at a loss.

Certificate Unknown

Hi,

I try to send a push notification to an iphone, but I have a problem with the certificate I think.
When I launch rake apn:notifications:deliver --trace
I obtain:
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
SSL_connect returned=1 errno=0 state=SSLv3 read finished A: sslv3 alert certificate unknown

When I convert the certificate with this command :
openssl pkcs12 -in Certificates.p12 -out apple_push_notification_development.pem -nodes -clcerts
It asks me to enter an Import Password.

After that I obtain this result: MAC verified OK

So I think it's ok. But actually no. I don't know why it doesn't work. Do you have any idea ?

Here is the ruby version I'm using: ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
I'm working on an Ubuntu Server version 9.10

Thanks.

Christophe

P.S: This is the first time I use Ruby.

rake aborted! invalid DER-encoded certificate data

I have followed all the steps for converting the Certificate but I am getting the

rake aborted!
invalid DER-encoded certificate data

Error all the time ...

Let me know what I am missing here...

Thanks
Bhushan Ahire

Message sending logic is extremely inefficient for large #s of devices

This loop is brutally slow - you're looping through EVERY device looking for messages to send! The old version just looked for notifications with sent_at nil. That is much faster, and I ended up downgrading when I realized what was happening:

    APN::Connection.open_for_delivery({:cert => the_cert}) do |conn, sock|
      APN::Device.find_each(:conditions => conditions) do |dev|
        dev.unsent_notifications.each do |noty|
          conn.write(noty.message_for_sending)
          noty.sent_at = Time.now
          noty.save
        end
      end
    end

undefined method `custom_properties' for #<APN::Notification:0x10f8919c>

I have been getting this error lately…

(in /home/webapps/[REDACTED]/releases/20110611190638)
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
Finding notifications with a device in zone -1 (offset of UTC) (more-or-less)
Found 82103 notifications
rake aborted!
undefined method `custom_properties' for #<APN::Notification:0x10f8919c>
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/activemodel-3.0.7/lib/active_model/attribute_methods.rb:367:in `method_missing'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.7/lib/active_record/attribute_methods.rb:46:in `method_missing'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:59:in `apple_hash'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:76:in `to_apple_json'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:81:in `message_for_sending'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:106:in `block (2 levels) in send_notifications'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:105:in `each'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:105:in `block in send_notifications'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/libs/connection.rb:60:in `open'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/libs/connection.rb:23:in `open_for_delivery'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bundler/gems/apn_on_rails-18f5d37397e3/lib/apn_on_rails/app/models/apn/notification.rb:104:in `send_notifications'
/home/webapps/[REDACTED]/releases/20110611190638/lib/tasks/apn.rake:46:in `block (3 levels) in <top (required)>'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/home/webapps/[REDACTED]/releases/20110611190638/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'

Rename create_groups.rb to create_apn_groups.rb

Hi,
In apn_on_rails v=0.5.1, the generators template for creating groups is called "create_groups.rb" which caused same name error for me.

Can this file be renamed to "create_apn_groups.rb" instead?

Broken pipe

Hello,
I'm getting this error while I'm trying to send push notifications to about 100 devices.

RAILS_ENV="production" rake apn:notifications:deliver
(in /home/breiko/public_html/iosmanager)
Broken pipe

What does this mean?

Unable to use APN with multiple apps because connection.rb hard-wired to use configatron

In lib/apn_on_rails/libs/connection.rb, the open private method uses configatron to get the APN cert, meaning it is impossible to actually use this gem to push from one server to multiple apps, even though the gem is supposed to be built that way.

Seems like configatron would be a reasonable option for applications that don't push to multiple apps, but this has to be more of a fallback than the ONLY way to specify a cert. Because each APN::App can have its own cert, that's where to look for the cert first, rather than looking in configatron.

Rails 3.2 and self.table_name

I'm not sure if this changed in 3.2 or I have something else interfering, but while trying to upgrade to 3.2.1, I see some test failures with something like "apn_bases does not exist" - and my guess is that the def self.table_name in APN base.rb used to return things like apn_devices, and now returns apn_bases incorrectly.

cannot uninstall

I don't need the gem anymore, but it is still creating the tables when I do a rake db:migrate, how can I keep that from happening.
I have removed the gem from the Gemfile and rakefile

last_registered_at documentation

Hello, first of all, thanks for your work and efforts on apn_on_rails. It's a great tool!

I've found your readme a bit confusing about last_registered_at field, that I suppose is really important.

Every time my app start I do something like:

Device.create(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz',:app_id=>1)

but this does not touch last_registered_at if the device already exist.

So i guess it's missing in your documentation how to touch last_registered_at field that I guess you can do with:

device = APN::Device.find(1)
device.set_last_registered_at
device.save

How did you go about getting your certs into the database?

::preface::
I couldn't find any specific resource on how to do this. And there isn't a wiki so I apologize If I posted this to the issues and that is not the correct place to do so.

::question::
I am wondering what the preferred approach for getting the dev and production certs into the database (APN::App) are. I was going to create a data migration which would create the one app I need, but I wanted to make sure I wasn't missing a better way to do this. Is there one?

::thanks::
Thanks for any feedback or suggestions as to how you did it.

Sending issues after upgrade with new pem file

Hi,
I recently upgraded to the 0.4.1 (was using 0.3.0) because I needed custom properties. I also changed the pem file for the app. Now when I send notifications, (using rake apn:notifications:deliver) it only sends a single notification at a time and the user doesn't receive it. If I switch back the pem files, everything is fine. I'm confused because I don't see any errors in the log and I don't get why it would send one and then stop.
I'm on rails 2.3.5 on heroku.

Thanks!

rake apn:notifications:deliver not able to send all notifications

I have records in apn_notifications table with NIL 'sent_at'.
But after running command
rake apn:notifications:deliver

Some still remains with sent_at as NIL.

Is there any issue with gem or my following code.

def perform
tracker = PushTracker.find(@tracker_id)
begin
notifications = APN::Notification.all(:conditions => 'sent_at IS NULL')
if(!notifications.empty?)
tracker.start_sending = Time.now if tracker.start_sending.nil?
tracker.end_sending = Time.now
tracker.sending = true
tracker.save!
#send the notifications
system "rake apn:notifications:deliver"
#set up another delayed job in the future in case they all didn't go through
Delayed::Job.enqueue(PushSender.new(@tracker_id),0, 5.minutes.from_now)
else
tracker.clean! if defined?(tracker) && !tracker.nil?
end
rescue => e
HoptoadNotifier.notify(
:error_class => "Push Sender",
:error_message => "Push Sender Error: #{e.message}",
:request => {:tracker => tracker, :exception => e}
)
tracker.clean! if defined?(tracker) && !tracker.nil?
end

end

Note: I am running above piece of code as heroku delayed job.

Any help would be appreciated.

Thnaks.

no such file to load -- apn_on_rails_tasks

Following the setup instructions, I've put this in my rakefile:

begin
require 'apn_on_rails_tasks'
rescue MissingSourceFile => e
puts e.message
end

But rake is not finding the file:

"no such file to load -- apn_on_rails_tasks "

I have the 0.4.0 version installed in vendor/gems/apn_on_rails-0.4.0/ so I was able to get around this problem by changing my rakefile to:

begin
require 'vendor/gems/apn_on_rails-0.4.0/lib/apn_on_rails_tasks'
rescue MissingSourceFile => e
puts e.message
end

But that's not very convenient. It seems like the gem isn't being included in my path.

FYI I'm using rails 2.1.

Child properties of the alert property

I don't see a way to add an alert dictionary in order to push a launch-image. When I add the following: {:question_id=>1234, :alert=>{"launch-image"=>"Default-AnswerReady.png"}}

APN is creating {:question_id => 1234, :alert => "launch-imageDefault-AnswerReady.png}

Login button

Should be placed underneath the input fields like before, and the forgot password can be moved further down on the page.

Fix confusing README.textile

I find it very confusing on this line...

app = APN::App.create(:apn_dev_cert => "PASTE YOUR DEV CERT HERE", :apn_prod_cert => "PASTE YOUR PROD CERT HERE")

The first thought I had when I saw "PASTE YOUR DEV CERT HERE" is to "Put the .cer file path in here". BUT! it is not! it should be the "content" of the .pem file. This is totally misleading and will cause newbies, like me, a lot of time to figure this out. I suggest you to change it to "PUT CONTENT OF .PEM FILE HERE - e.g. File.read('config/apn.pem')", so it would be much clearer.

And also you should tell to initialize RAILS_ROOT, APN::App::RAILS_ENV='development' in "config/configatron/development.rb and production.rb" as well. There will be a lot of iOS devs that don't know any ruby on rails come and pick this up and don't know how to do this.

And cannot use "~" sign for specifying directories, have to type in full path.

Regards

Only the first notification in each batch is being sent

If more than one notification is sent over the connection at a time, only the first one arrives and all others are ignored.

I've tested by setting up two devices and dispatching a single notification to each of them which works perfectly. If I batch two at once, only one device receives the notification.

This also applies to group notification. If there is more than one device in the group, only the first device is notified.

New Changes to Push Certificates — Action Needed?

Apple has been sent out this email which describes changes to the certificates. Do we need to regenerate our certificates in the app?

Important changes to Apple Push Notification certificates

Dear Developer,
On December 22, 2010, the production Apple Push Notification service will begin to use a 2048-bit TLS/SSL certificate that provides a more secure connection between your provider server and the Apple Push Notification service.

To ensure you can continue to validate your server's connection to the Apple Push Notification service, you will need to update your push notification server with a copy of the 2048-bit root certificate from Entrust's website. This will not require a change to your iOS apps -- this update only applies to provider servers.

If you have been successfully validating the certificate chain in the APNs sandbox environment, you already have the root certificate you need. Simply install the same
root certificate on your production push provider servers.

More details on validating your provider communication channel can be found in the Provider Communication with Apple Push Notification service section of the Local and Push Notification Programming Guide.

Neither PUB key nor PRIV key:: not enough data

rake apn:notifications:deliver
(in /var/rails/Push)
Neither PUB key nor PRIV key:: not enough data
rake aborted!

Debian Squeeze

ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

rails -v
Rails 3.2.5

I really can't find where my problem come from.

Any solution?

Cannot send notification because of Broken Pipe error

Hey!

I have a problem with the gem, and maybe it's because of how I use it.

I didn't create any APN::App, I use APN::Device and APN::Notification to send individual notifications.
My problem is that I always register an Broken Pipe exception when I try to send like 10 notifications ... and I don't know why it happens, or how to fix that?

Then, when an exception is raised, we have no way to know which notification object raised this exception ... I would like to know it to mark it as "raising an exception" and so I'll not try to send it again, is it possible?

Thanks you in advance for your help!

Jeremy.

Error creating an APN::Device

I am new to this GEM, so please excuse the NEWBIE questions.

I am using the 0.4.1 version. I cannot seem to get a proper ID assigned to any APN::Device I create. I've whittled the problem down to the following steps in the console.

I don't understand what I did that would cause the device to have no ID and fail on the save.

Any thoughts?

poweruser$ script/console
Loading development environment (Rails 2.3.5)
console> require 'apn_on_rails'
=> []

console> app = APN::App.create(:apn_dev_cert => "DEV", :apn_prod_cert => "PROD")
=> #<APN::App id: 2, apn_dev_cert: "DEV", apn_prod_cert: "PROD", created_at: "2011-01-23 14:48:52", updated_at: "2011-01-23 14:48:52">

console> app.save
=> true

console> device = APN::Device.create(:token => 'aaaa', :app_id => app.id)
=> #<APN::Device id: nil, token: "aaaa", created_at: nil, updated_at: nil, last_registered_at: nil, app_id: 2>

console> device.save
=> false

apn:install generator not working on rails 2.3.14

Hi,

I guess the first question is - is Rails 2 no longer supported? If not, I'd recommend noting in the readme

my environment is

apn_on_rails 0.5.1 gem via bundler 1.1.3
Rails 2.3.14
Ruby 1.9.2-p290

I have require "apn_on_rails" in an initializer
I have require "apn_on_rails_tasks" in the Rakefile

~/my_app: bundle exec ./script/generate apn_on_rails:install
Couldn't find 'apn_on_rails:install' generator

The gem appears to be loaded in some form

~/my_app: bundle exec ./script/console
Loading development environment (Rails 2.3.14)  
>> APN.class
=> Module

clarification in configuration documentation

Since keys are configured per APN::App model, not via configutron, I'm confused by the documentation which has me using configatron.

Do I still need to use configatron to configure the host? Can you please update the front page documentation to clarify, removing any parameters that aren't used.

Cannot find generator

First, thanks for taking over this project. We've been using it for about year. We're just updating to Rails 3.0.1 and trying to install 0.4.1 of apn_on_rails, everything seems to work but can't run the migration using this: rails g apn_migrations

Is this a known issue or is it me?

apn_bases table not exist

I am using rails 3.2.8
Is i want to add maunally this table "apn_bases" into my database.

Mysql2::Error: Table test_development.apn_bases' doesn't exist: SHOW FULL FIELDS FROM apn_bases

App id

Can you show an example of creating the APN::App and storing the keys on it.

what's the intended behavior of apn_device.last_registered_at ?

from lib/app/models/device.rb

Line 20 is a bit confusing:

before_save :set_last_registered_at

Because the method set_last_registred_at only updates the time when the time wasn't previously set. Is this the intended behavior?

My suggestion, is to either make it before_create, or get rid of the nil check in set_last_registered_at. The first suggestion would mostly mimic the current behavior in a more coherent way, whereas the second suggestion would behave as I expected it (updating the last_registered_at value at each save).

I could submit a pull request if we can agree on a convention.

Group notification example

heyy
can u provide a group notification example??
and if it is necessary to hav the token of the all devices to which group notification is to be send??

Regards,
Amit Hooda

uninitialized constant APN::App::RAILS_ENV

Hi there, Rails noob here and I'm struggling trying to figure out how to solve this error. It's barking about the RAILS_ENV variable. I've tried a couple of forks that change this to Rails.env but I still get the same error. I don't know enough about rails to dig in any further and I was hoping you could point me in the right direction.

air:apnapp azcoov$ rake apn:notifications:deliver --trace
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/version.rb:2: warning: already initialized constant VERSION
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
rake aborted!
uninitialized constant APN::App::RAILS_ENV
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:11:in `cert'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:22:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:32:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `each'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/rails/../tasks/apn.rake:7
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => apn:notifications:deliver

Can't make app = APN::App.create(:apn_dev_cert => "MY_DEV_CERT.pem", :apn_prod_cert => "MY_PROD_CERT.pem")

Hi, I'm working with Ruby 1.9.2, Rails 3.2.3 and apn_on_rails 0.5.1 to implement push notifications in my application.

When I run:

app = APN::App.create(:apn_dev_cert => "MY_DEV_CERT.pem", :apn_prod_cert => "MY_PROD_CERT.pem")

I get the following error:

ActiveModel :: MassAssignmentSecurity :: Error: Can not mass-assign protected attributes: apn_dev_cert, apn_prod_cert

Does anyone know what does it mean? Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.