Not able to send notification
forever-sumit opened this issue · 16 comments
Hi ,
I want to send notification form my client web app to mobile app. currently I'm working for IOS app.
My client provide me "cert.p12" file.
and I've generate a .pem file using your given command.
In my rails application, I've created a configuration file where I set the host, pem file path
APNS.host = 'gateway.sandbox.push.apple.com'
APNS.pem = '/home/sumit/rails_work/billy/provision/cert.pem'
and now from my model I try to send notification with dummy devise token. for that I've write the following line
device_token = '123abc456def'
APNS.send_notification(device_token, 'Hello iPhone!' )
when the 'send_notification' method call, I've got the following error.
NoMethodError: undefined method `close' for nil:NilClass
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:83:in `rescue in with_connection'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:72:in `with_connection'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:42:in `block in send_notifications'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:41:in `synchronize'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:41:in `send_notifications'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:37:in `send_notification'
from (irb):11
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/railties-4.0.8/lib/rails/commands/console.rb:90:in `start'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/railties-4.0.8/lib/rails/commands/console.rb:9:in `start'
from /home/sumit/.rvm/gems/ruby-2.1.2@store/gems/railties-4.0.8/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I'm a web developer, I've no Idea about mobile development.
Please let me know where I'm doing wrong.
Same problem here
I've run into this before as well. Ensure your PEM is correctly formatted and reachable by the Rails app. Every time I've had this issue it was because the pem was corrupt, missing, or incomplete (in the case where the mobile team forgot to export the certificate with the private key).
Yup it was the pem problem, it's fixed now, I can share the steps with the help of which I generated the push notification certificate if anyone requires that
Did they differ from https://github.com/NicosKaralis/pushmeup#apns-apple-ios
A bit different, I just exported the private key instead of selecting both
We should probably raise an exception if the pem file can not be found, shouldn't let the gem crap out.
+1 for this issue! I've tried exporting all possible combinations (certificate + private key, only certificate and only private key) and still not working.
iOS notifications are working properly from my local computer though, but not working on my application server - this is really strange.
Ok, I resolved issue.
If you trying to use APNs notifications from production server - check your firewall.
Port 2195 MUST BE OPENED IN FIREWALL.
You can test the connectivity to apple service by running:
telnet gateway.sandbox.push.apple.com 2195
Successful message would be like:
Trying 17.172.232.45...
Connected to gateway.sandbox.push.apple.com.
Escape character is '^]'.
If there is no connection after invoking the command you have a problem.
Problem found, if anyone else is having this problem I'll reopen later
Getting same error. I have my pem file, generated from private + certificate.
My Code:
title = 'Hello'
user = User.find(29)
APNS.port = 2195
APNS.pass = 'XYZ'
APNS.host = 'gateway.sandbox.push.apple.com'
APNS.pem = '/home/niraj/Downloads/pushcert_new.pem'
data = APNS.send_notification(user.device_id, title)
Error log:
NoMethodError: undefined method `close' for nil:NilClass
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:83:in `rescue in with_connection'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:72:in `with_connection'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:42:in `block in send_notifications'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:41:in `synchronize'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:41:in `send_notifications'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pushmeup-0.3.0/lib/pushmeup/apns/core.rb:37:in `send_notification'
from (irb):16
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:90:in `start'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:9:in `start'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:69:in `console'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
... 1 levels...
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/commands/rails.rb:6:in `call'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/command_wrapper.rb:38:in `call'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:180:in `block in serve'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:153:in `fork'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:153:in `serve'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/niraj/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
@nirajmchauhan is your pem file generated on mac machine with the help of cert file and p12 file?
and make sure you use the development cert to generate the development pem file.
@forever-sumit Yes my pem file was generated in mac book pro, I selected private + certificate to export it as p12 and then converted it to pem.
This gem is working perfectly, the problem is with your certificates, make
sure that you are generating certificates using push notification
certificates
On Jan 21, 2015 12:55 PM, "Niraj" notifications@github.com wrote:
@forever-sumit https://github.com/forever-sumit Yes my pem file was
generated in mac book pro, I selected private + certificate to export it as
p12 and then converted it to pem.—
Reply to this email directly or view it on GitHub
#47 (comment)
.
So I finally ended up deleting all certificates, identifiers, prov profiles and recreated them. It worked.
So only problem I am facing now is that somehow my IPAD is getting notification but sound is not coming. I tried following codes:
APNS.send_notification(user.device_id, 'Hello IPhone')
APNS.send_notification(user.device_id, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
APNS.send_notification(user.device_id, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default', :other => {:sent => 'with apns gem', :custom_param => "value"})
But nothing is producing notification sound.
Do you have a sound file called default
? If you do check the volume of notifications and alerts
If you have any sound called default
any of the calls will make sound, if you do not I can't guarantee that on the second and third call any sound will be made, but the first one will always make the "standard" alert sound
I'm having the same problem with the gem. The APNS.send_notification call does not fail consistently but every now and then I get exactly the same error in production.
undefined method close' for nil:NilClass /data/apps/VC/shared/bundle/ruby/2.1.0/bundler/gems/pushmeup-38260c8df74b/lib/pushmeup/apns/core.rb:83:in
rescue in with_connection'
/data/apps/VC/shared/bundle/ruby/2.1.0/bundler/gems/pushmeup-38260c8df74b/lib/pushmeup/apns/core.rb:72:in with_connection' /data/apps/VC/shared/bundle/ruby/2.1.0/bundler/gems/pushmeup-38260c8df74b/lib/pushmeup/apns/core.rb:42:in
block in send_notifications'
/data/apps/VC/shared/bundle/ruby/2.1.0/bundler/gems/pushmeup-38260c8df74b/lib/pushmeup/apns/core.rb:41:in synchronize' /data/apps/VC/shared/bundle/ruby/2.1.0/bundler/gems/pushmeup-38260c8df74b/lib/pushmeup/apns/core.rb:41:in
send_notifications'
/data/apps/VC/shared/bundle/ruby/2.1.0/bundler/gems/pushmeup-38260c8df74b/lib/pushmeup/apns/core.rb:37:in `send_notification'