Class: NotifyUser::Apns
- Inherits:
-
Object
- Object
- NotifyUser::Apns
- Defined in:
- app/models/notify_user/apns.rb
Constant Summary collapse
- SYMBOL_NAMES_SIZE =
10- PAYLOAD_LIMIT =
255
Class Method Summary collapse
-
.push_notification(notification) ⇒ Object
sends push notification.
Class Method Details
.push_notification(notification) ⇒ Object
sends push notification
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/notify_user/apns.rb', line 7 def self.push_notification(notification) #calculates the bytes already used used_space = SYMBOL_NAMES_SIZE + notification.id.size + notification.created_at.to_time.to_i.size + notification.type.size used_space += notification.params[:action_id].size if notification.params[:action_id] space_allowance = PAYLOAD_LIMIT - used_space payload = { :alias => notification.target_id, :aps => {alert: notification.(space_allowance), badge: notification.count_for_target}, :n_data => { '#' => notification.id, t: notification.created_at.to_time.to_i, '?' => notification.type } } payload[:n_data]['!'] = notification.params[:action_id] if notification.params[:action_id] response = Urbanairship.push(payload) if response.success? Rails.logger.info "Push notification sent successfully." return true else Rails.logger.info "Push notification failed." return false end end |