Merge pull request #194 from silasj/version-1.0

Make PushNotification object a bit smarter
This commit is contained in:
Jamon Holmgren
2013-07-03 10:30:48 -07:00
4 changed files with 23 additions and 11 deletions

View File

@@ -53,4 +53,9 @@ namespace :spec do
App.config.instance_variable_set("@spec_files", spec_files)
Rake::Task["simulator"].invoke
end
end
task :sim_close do
sh "osascript -e 'tell application \"iphone simulator\" to quit'"
end

View File

@@ -5,7 +5,7 @@ module ProMotion
def check_for_push_notification(options)
if options && options[UIApplicationLaunchOptionsRemoteNotificationKey]
received_push_notification options[UIApplicationLaunchOptionsRemoteNotificationKey]
received_push_notification options[UIApplicationLaunchOptionsRemoteNotificationKey], true
end
end
@@ -38,9 +38,9 @@ module ProMotion
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
@@ -54,7 +54,7 @@ module ProMotion
end
def application(application, didReceiveRemoteNotification:notification)
received_push_notification(notification)
received_push_notification(notification, false)
end
end

View File

@@ -31,20 +31,27 @@ module ProMotion
aps["sound"] if aps
end
def method_missing(method, *args, &block)
aps[method.to_s] || aps[method.to_sym] || self.notification[method.to_s] || self.notification[method.to_sym] || super
end
# For testing from the REPL
# > PM::PushNotification.simulate alert: "My test message", badge: 4
def self.simulate(args = {})
UIApplication.sharedApplication.delegate.on_push_notification self.fake_notification(args)
UIApplication.sharedApplication.delegate.on_push_notification self.fake_notification(args), args[:launched]
end
def self.fake_notification(args = {})
self.new({
"aps" => {
"alert" => args[:alert] || "Test Push Notification",
"badge" => args[:badge] || 2,
"sound" => args[:sound] || "default"
}
})
"alert" => args.delete(:alert) || "Test Push Notification",
"badge" => args.delete(:badge) || 2,
"sound" => args.delete(:sound) || "default"
},
"channels" => args.delete(:channels) || [
"channel_name"
]
}.merge(args))
end
end

View File

@@ -13,7 +13,7 @@ describe "PM::Delegate" do
it "should handle push notifications" do
@subject.mock!(:on_push_notification) do |notification|
@subject.mock!(:on_push_notification) do |notification, was_launched|
notification.should.be.kind_of(PM::PushNotification)
notification.alert.should == "Eating Bacon"
notification.badge.should == 42