Class: APN::Device

Inherits:
Base
  • Object
show all
Defined in:
lib/apn_on_rails/app/models/apn/device.rb

Overview

Represents an iPhone (or other APN enabled device). An APN::Device can have many APN::Notification.

In order for the APN::Feedback system to work properly you MUST touch the last_registered_at column everytime someone opens your application. If you do not, then it is possible, and probably likely, that their device will be removed and will no longer receive notifications.

Example:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

table_name

Instance Attribute Details

#feedback_atObject

The feedback_at accessor is set when the device is marked as potentially disconnected from your application by Apple.



23
24
25
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 23

def feedback_at
  @feedback_at
end

Instance Method Details

#to_hexaObject

Returns the hexadecimal representation of the device’s token.



39
40
41
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 39

def to_hexa
  [self.token.delete(' ')].pack('H*')
end

#token=(token) ⇒ Object

Stores the token (Apple’s device ID) of the iPhone (device).

If the token comes in like this:

'<5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz>'

Then the ‘<’ and ‘>’ will be stripped off.



30
31
32
33
34
35
36
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 30

def token=(token)
  res = token.scan(/\<(.+)\>/).first
  unless res.nil? || res.empty?
    token = res.first
  end
  write_attribute('token', token)
end