Sha256: abd8c18380d11b9227620a85edfb51379851f310b48b0bf599ef3de050027e5c
Contents?: true
Size: 1.22 KB
Versions: 11
Compression:
Stored size: 1.22 KB
Contents
module NotifyUser class Apns SYMBOL_NAMES_SIZE = 10 PAYLOAD_LIMIT = 255 #sends push notification 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.mobile_message(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 end end
Version data entries
11 entries across 11 versions & 1 rubygems