Ruby On Rails IOS Push Notifications

I need to send push notifications to mobile iOS.

I used apn_on_rails to send these notifications.

I get my pem file from an iOS developer. I made the following configurations:

In Productions and development in config / configtran / *. rb

RAILS_ROOT, APN::App::RAILS_ENV='production'
configatron.apn.passphrase  = 'leo_123'
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')

And then I created one Notificationby following the documentation.

After I executed the following commands, it fits perfectly and responds

From console

APN :: App.send_notifications

Use rake RAILS_ENV = production rake apn: notifications: deliver

I tried this both in a production environment and in a development environment. After this line, it does not respond. I also did not find anything in the magazine.

APN::App Load (0.1ms)  SELECT "apn_apps".* FROM "apn_apps"

. ?

.

+4
1

grocer gem.

pusher = Grocer.pusher(certificate: "#{Rails.root}/lib/dev_cert.pem", # required
                       passphrase:  "XXXXXX",                         # optional
                       gateway:     "gateway.sandbox.push.apple.com", # optional
                       port:        2195,                             #optional
                       retries:     3)

feedback = Grocer.feedback( certificate: "#{Rails.root}/lib/dev_cert.pem", 
                                  passphrase:  "XXXXXX",                        
                                  gateway:     "feedback.sandbox.push.apple.com", 
                                  port:        2196,                     
                                  retries:     3)

 notification = Grocer::Notification.new(
    device_token:      push_id,
    alert:             message,
    badge:             3,
    sound:             "siren.aiff",         # optional
    expiry:            Time.now + 60*60,     # optional; 0 is default, meaning the message is not stored
    # identifier:        1234,                 # optional
    content_available: true                  # optional; any truthy value will set 'content-available' to 1
  )

  feedback.each do |attempt|
    puts "Device #{attempt.device_token} failed at #{attempt.timestamp}"
  end

  pusher.push(notification)
+5

Source: https://habr.com/ru/post/1543860/


All Articles