lib/ProMotion/delegate/delegate_notifications.rb in ProMotion-0.7.8 vs lib/ProMotion/delegate/delegate_notifications.rb in ProMotion-1.0.0
- old
+ new
@@ -3,23 +3,20 @@
attr_accessor :aps_notification
def check_for_push_notification(options)
if options && options[UIApplicationLaunchOptionsRemoteNotificationKey]
- received_push_notification options[UIApplicationLaunchOptionsRemoteNotificationKey]
+ received_push_notification options[UIApplicationLaunchOptionsRemoteNotificationKey], true
end
end
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
- types = types | UIRemoteNotificationTypeBadge if notification_types.include?(:badge)
- types = types | UIRemoteNotificationTypeSound if notification_types.include?(:sound)
- types = types | UIRemoteNotificationTypeAlert if notification_types.include?(:alert)
- types = types | UIRemoteNotificationTypeNewsstandContentAvailability if notification_types.include?(:newsstand)
+ notification_types.each { |t| types = types | map_notification_symbol(t) }
UIApplication.sharedApplication.registerForRemoteNotificationTypes types
end
def unregister_for_push_notifications
@@ -36,13 +33,13 @@
types << :newsstand if mask & UIRemoteNotificationTypeNewsstandContentAvailability
types
end
- def received_push_notification(notification)
+ def received_push_notification(notification, was_launched)
@aps_notification = PM::PushNotification.new(notification)
- on_push_notification(@aps_notification) if respond_to?(:on_push_notification)
+ on_push_notification(@aps_notification, was_launched) if respond_to?(:on_push_notification)
end
# CocoaTouch
def application(application, didRegisterForRemoteNotificationsWithDeviceToken:device_token)
@@ -52,10 +49,22 @@
def application(application, didFailToRegisterForRemoteNotificationsWithError:error)
on_push_registration(nil, error) if respond_to?(:on_push_registration)
end
def application(application, didReceiveRemoteNotification:notification)
- received_push_notification(notification)
+ received_push_notification(notification, false)
+ end
+
+ protected
+
+ def map_notification_symbol(symbol)
+ {
+ none: UIRemoteNotificationTypeNone,
+ badge: UIRemoteNotificationTypeBadge,
+ sound: UIRemoteNotificationTypeSound,
+ alert: UIRemoteNotificationTypeAlert,
+ newsstand: UIRemoteNotificationTypeNewsstandContentAvailability
+ }[symbol] || UIRemoteNotificationTypeNone
end
end
end