Module: ProMotion::DelegateNotifications

Included in:
DelegateModule
Defined in:
lib/ProMotion/delegate/delegate_notifications.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aps_notificationObject

Returns the value of attribute aps_notification.



4
5
6
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 4

def aps_notification
  @aps_notification
end

Instance Method Details

#application(application, didReceiveRemoteNotification: notification) ⇒ Object

CocoaTouch



45
46
47
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 45

def application(application, didRegisterForRemoteNotificationsWithDeviceToken:device_token)
  on_push_registration(device_token, nil) if respond_to?(:on_push_registration)
end

#check_for_push_notification(options) ⇒ Object



6
7
8
9
10
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 6

def check_for_push_notification(options)
  if options && options[UIApplicationLaunchOptionsRemoteNotificationKey]
    received_push_notification options[UIApplicationLaunchOptionsRemoteNotificationKey], true
  end
end

#received_push_notification(notification, was_launched) ⇒ Object



38
39
40
41
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 38

def received_push_notification(notification, was_launched)
  @aps_notification = PM::PushNotification.new(notification)
  on_push_notification(@aps_notification, was_launched) if respond_to?(:on_push_notification)
end

#register_for_push_notifications(*notification_types) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 12

def register_for_push_notifications(*notification_types)
  notification_types = Array.new(notification_types)
  notification_types = [ :badge, :sound, :alert, :newsstand ] if notification_types.include?(:all)

  types = UIRemoteNotificationTypeNone
  notification_types.each { |t| types = types | map_notification_symbol(t) }

  UIApplication.sharedApplication.registerForRemoteNotificationTypes types
end

#registered_push_notificationsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 26

def registered_push_notifications
  mask = UIApplication.sharedApplication.enabledRemoteNotificationTypes
  types = []

  types << :badge     if mask & UIRemoteNotificationTypeBadge > 0
  types << :sound     if mask & UIRemoteNotificationTypeSound > 0
  types << :alert     if mask & UIRemoteNotificationTypeAlert > 0
  types << :newsstand if mask & UIRemoteNotificationTypeNewsstandContentAvailability > 0

  types
end

#unregister_for_push_notificationsObject



22
23
24
# File 'lib/ProMotion/delegate/delegate_notifications.rb', line 22

def unregister_for_push_notifications
  UIApplication.sharedApplication.unregisterForRemoteNotifications
end