Class: APN::Device
- 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
-
#feedback_at ⇒ Object
The
feedback_at
accessor is set when the device is marked as potentially disconnected from your application by Apple.
Instance Method Summary collapse
- #set_last_registered_at ⇒ Object
-
#to_hexa ⇒ Object
Returns the hexadecimal representation of the device’s token.
-
#token=(token) ⇒ Object
Stores the token (Apple’s device ID) of the iPhone (device).
Methods inherited from Base
Instance Attribute Details
#feedback_at ⇒ Object
The feedback_at
accessor is set when the device is marked as potentially disconnected from your application by Apple.
26 27 28 |
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 26 def feedback_at @feedback_at end |
Instance Method Details
#set_last_registered_at ⇒ Object
46 47 48 |
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 46 def set_last_registered_at self.last_registered_at = Time.now #if self.last_registered_at.nil? end |
#to_hexa ⇒ Object
Returns the hexadecimal representation of the device’s token.
42 43 44 |
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 42 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.
33 34 35 36 37 38 39 |
# File 'lib/apn_on_rails/app/models/apn/device.rb', line 33 def token=(token) res = token.scan(/\<(.+)\>/).first unless res.nil? || res.empty? token = res.first end write_attribute('token', token) end |