Skip to content

Commit

Permalink
Added support for different default implementations of delegate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasper Kolenc authored and Gasper Kolenc committed Mar 13, 2016
1 parent dbe9c5a commit e079306
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PushReview.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "PushReview"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "New unobtrusive way of asking users to leave a review on the App Store."
s.description = <<-DESC
PushReview is a library aimed at getting your app the reviews it deserves. It asks users for an App Store review when they are done using the app and are in an idle state.
Expand Down
31 changes: 23 additions & 8 deletions Source/PushReview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ extension PushReview: UIAlertViewDelegate {
dispatch_once(&Static.token) {
swizzle(originalSelector: Selector("application:didReceiveLocalNotification:"), swizzledSelector: Selector("pushReview_application:didReceiveLocalNotification:"))
swizzle(originalSelector: Selector("application:didReceiveRemoteNotification:fetchCompletionHandler:"), swizzledSelector: Selector("pushReview_application:didReceiveRemoteNotification:fetchCompletionHandler:"))
swizzle(originalSelector: Selector("application:handleActionWithIdentifier:forRemoteNotification:completionHandler:"), swizzledSelector: Selector("pushReview_application:handleActionWithIdentifier:forRemoteNotification:completionHandler:"))
swizzle(originalSelector: Selector("application:handleActionWithIdentifier:forLocalNotification:completionHandler:"), swizzledSelector: Selector("pushReview_application:handleActionWithIdentifier:forLocalNotification:completionHandler:"))
swizzle(originalSelector: Selector("application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler:"), swizzledSelector: Selector("pushReview_application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler:"))
swizzle(originalSelector: Selector("application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:"), swizzledSelector: Selector("pushReview_application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:"))
}
}

Expand Down Expand Up @@ -425,6 +425,9 @@ extension UIResponder {
pushReview_application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
shouldCallCompletionHandler = false
}
if respondsToSelector(Selector("application:didReceiveRemoteNotification:")) {
(self as? UIApplicationDelegate)?.application?(application, didReceiveRemoteNotification: userInfo)
}

PushReview.didReceiveNotification(userInfo["aps"] as? [NSObject : AnyObject])

Expand All @@ -433,12 +436,18 @@ extension UIResponder {
}
}

@objc private func pushReview_application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {
@objc private func pushReview_application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
var shouldCallCompletionHandler = true
if respondsToSelector(Selector("pushReview_application:handleActionWithIdentifier:forLocalNotification:completionHandler:")) {
pushReview_application(application, handleActionWithIdentifier: identifier, forLocalNotification: notification, completionHandler: completionHandler)
if respondsToSelector(Selector("pushReview_application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:")) {
pushReview_application(application, handleActionWithIdentifier: identifier, forLocalNotification: notification, withResponseInfo: responseInfo, completionHandler: completionHandler)
shouldCallCompletionHandler = false
}
if respondsToSelector(Selector("application:handleActionWithIdentifier:forLocalNotification:completionHandler:")) {
if #available(iOS 8.0, *) {
(self as? UIApplicationDelegate)?.application?(application, handleActionWithIdentifier: identifier, forLocalNotification: notification, completionHandler: completionHandler)
shouldCallCompletionHandler = false
}
}

PushReview.handleActionWithIdentifier(identifier, forNotification: notification.userInfo)

Expand All @@ -447,12 +456,18 @@ extension UIResponder {
}
}

@objc private func pushReview_application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
@objc private func pushReview_application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
var shouldCallCompletionHandler = true
if respondsToSelector(Selector("pushReview_application:handleActionWithIdentifier:forRemoteNotification:completionHandler:")) {
pushReview_application(application, handleActionWithIdentifier: identifier, forRemoteNotification: userInfo, completionHandler: completionHandler)
if respondsToSelector(Selector("pushReview_application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler:")) {
pushReview_application(application, handleActionWithIdentifier: identifier, forRemoteNotification: userInfo, withResponseInfo: responseInfo, completionHandler: completionHandler)
shouldCallCompletionHandler = false
}
if respondsToSelector(Selector("application:handleActionWithIdentifier:forRemoteNotification:completionHandler:")) {
if #available(iOS 8.0, *) {
(self as? UIApplicationDelegate)?.application?(application, handleActionWithIdentifier: identifier, forRemoteNotification: userInfo, completionHandler: completionHandler)
shouldCallCompletionHandler = false
}
}

PushReview.handleActionWithIdentifier(identifier, forNotification: userInfo["aps"] as? [NSObject : AnyObject])

Expand Down

0 comments on commit e079306

Please sign in to comment.