Skip to content

Commit

Permalink
Fix logic when calling delegate methods from multiple services, so th…
Browse files Browse the repository at this point in the history
…at they're never short-circuited.
  • Loading branch information
stephanecopin committed May 15, 2017
1 parent 3ae9dba commit 4119d03
Showing 1 changed file with 63 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
public var window: UIWindow?

open var services: [ApplicationService] { return [] }
private lazy var __services: [ApplicationService]! = {
private lazy var __services: [ApplicationService] = {
return self.services
}()

Expand All @@ -30,18 +30,24 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {

@available(iOS 6.0, *)
public func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

return __services.reduce(true) { (previous, service) -> Bool in
previous && (service.application?(application, willFinishLaunchingWithOptions: launchOptions) ?? true)
var result = false
for service in __services {
if service.application?(application, willFinishLaunchingWithOptions: launchOptions) ?? false {
result = true
}
}
return result
}

@available(iOS 3.0, *)
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

return __services.reduce(true) { (previous, service) -> Bool in
previous && (service.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? true)
var result = false
for service in __services {
if service.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? false {
result = true
}
}
return result
}


Expand All @@ -61,23 +67,35 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {

@available(iOS, introduced: 2.0, deprecated: 9.0, message: "Please use application:openURL:options:")
public func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
return __services.reduce(true) { (previous, service) -> Bool in
previous && (service.application?(application, handleOpen: url) ?? true)
var result = false
for service in __services {
if service.application?(application, handleOpen: url) ?? false {
result = true
}
}
return result
}

@available(iOS, introduced: 4.2, deprecated: 9.0, message: "Please use application:openURL:options:")
public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return __services.reduce(true) { (previous, service) -> Bool in
previous && (service.application?(application, open: url, sourceApplication: sourceApplication, annotation: annotation) ?? true)
public func application(_ application: UIApplication, public url: URL, sourceApplication: String?, annotation: Any) -> Bool {

This comment has been minimized.

Copy link
@adamchalmers

adamchalmers May 23, 2017

I suspect the argument being renamed "public" from "open" here has caused a major bug.

var result = false
for service in __services {
if service.application?(application, open: url, sourceApplication: sourceApplication, annotation: annotation) ?? false {
result = true
}
}
return result
}

@available(iOS 9.0, *)
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return __services.reduce(true) { (previous, service) -> Bool in
previous && (service.application?(app, open: url, options: options) ?? true)
public func application(_ app: UIApplication, public url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
var result = false
for service in __services {
if service.application?(app, open: url, options: options) ?? false {
result = true
}
}
return result
}

@available(iOS 2.0, *)
Expand Down Expand Up @@ -304,9 +322,13 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
// If unimplemented, the default behavior is to allow the extension point identifier.
@available(iOS 8.0, *)
public func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
return __services.reduce(true) { (previous, service) -> Bool in
previous && (service.application?(application, shouldAllowExtensionPointIdentifier: extensionPointIdentifier) ?? true)
var result = false
for service in __services {
if service.application?(application, shouldAllowExtensionPointIdentifier: extensionPointIdentifier) ?? true {
result = true
}
}
return result
}


Expand All @@ -323,16 +345,24 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {

@available(iOS 6.0, *)
public func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
return __services.reduce(false) { (previous, service) -> Bool in
previous || (service.application?(application, shouldSaveApplicationState: coder) ?? false)
var result = false
for service in __services {
if service.application?(application, shouldSaveApplicationState: coder) ?? false {
result = true
}
}
return result
}

@available(iOS 6.0, *)
public func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
return __services.reduce(false) { (previous, service) -> Bool in
previous || (service.application?(application, shouldRestoreApplicationState: coder) ?? false)
var result = false
for service in __services {
if service.application?(application, shouldRestoreApplicationState: coder) ?? false {
result = true
}
}
return result
}

@available(iOS 6.0, *)
Expand All @@ -356,9 +386,13 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
// or application:didFailToContinueUserActivityWithType:error: if an error was encountered.
@available(iOS 8.0, *)
public func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {
return __services.reduce(false) { (previous, service) -> Bool in
previous || (service.application?(application, willContinueUserActivityWithType: userActivityType) ?? false)
var result = false
for service in __services {
if service.application?(application, willContinueUserActivityWithType: userActivityType) ?? false {
result = true
}
}
return result
}


Expand All @@ -368,9 +402,13 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
// restoreUserActivityState on all objects.
@available(iOS 8.0, *)
public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Swift.Void) -> Bool {
return __services.reduce(false) { (previous, service) -> Bool in
previous || (service.application?(application, continue: userActivity, restorationHandler: restorationHandler) ?? false)
var result = false
for service in __services {
if service.application?(application, continue: userActivity, restorationHandler: restorationHandler) ?? false {
result = true
}
}
return result
}


Expand Down

0 comments on commit 4119d03

Please sign in to comment.