Module: APN::Feedback

Defined in:
lib/apn_on_rails/libs/feedback.rb

Overview

Module for talking to the Apple Feedback Service. The service is meant to let you know when a device is no longer registered to receive notifications for your application.

Class Method Summary collapse

Class Method Details

.devices(cert, &block) ⇒ Object

Returns an Array of APN::Device objects that has received feedback from Apple. Each APN::Device will have it's feedback_at accessor marked with the time that Apple believes the device de-registered itself.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apn_on_rails/libs/feedback.rb', line 13

def devices(cert, &block)
  devices = []
  return if cert.nil? 
  APN::Connection.open_for_feedback({:cert => cert}) do |conn, sock|          
    while line = conn.read(38)   # Read 38 bytes from the SSL socket
      feedback = line.unpack('N1n1H140')            
      token = feedback[2].scan(/.{0,8}/).join(' ').strip
      device = APN::Device.find(:first, :conditions => {:token => token})
      if device
        device.feedback_at = Time.at(feedback[0])
        devices << device
      end
    end
  end
  devices.each(&block) if block_given?
  return devices
end

.process_devicesObject

devices


31
32
33
34
# File 'lib/apn_on_rails/libs/feedback.rb', line 31

def process_devices
  ActiveSupport::Deprecation.warn("The method APN::Feedback.process_devices is deprecated.  Use APN::App.process_devices instead.")
  APN::App.process_devices
end