Skip to content

Commit

Permalink
Add openURL callback
Browse files Browse the repository at this point in the history
  • Loading branch information
hartlco committed May 12, 2019
1 parent efdd26b commit 8ca2a58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion AppDelegateComponent.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AppDelegateComponent'
s.version = '0.0.1'
s.version = '0.0.2'
s.summary = 'Split functionality in AppDelegate into smaller components'
s.description = 'Provides a easy way to split functionality used in AppDelegate callbacks into small components'

Expand Down
21 changes: 18 additions & 3 deletions AppDelegateComponent/Classes/AppDelegateComponent.swift
Expand Up @@ -7,12 +7,17 @@ import UIKit
public protocol AppDelegateComponent {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool
}

extension AppDelegateComponent {
// Default implementations
public extension AppDelegateComponent {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
// Empty default implementation
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) { }

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return true
}
}

Expand All @@ -31,4 +36,14 @@ final public class AppDelegateComponentRunner {
didFinishLaunchingWithOptions: launchOptions)
}
}

public func componentStore(_ componentStore: AppDelegateComponentStore,
app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {

return componentStore.storedComponents.reduce(false, { result, component in
return result || component.application(app, open: url, options: options)
})
}
}

0 comments on commit 8ca2a58

Please sign in to comment.