-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add URLOpener
protocol for mocking UIApplication.shared
#1148
Conversation
} else { | ||
application.open(appStoreURL) | ||
} | ||
application.open(appStoreURL, options: [:], completionHandler: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take it or leave it, but if we want to provide defaults like open
in UIApplication
we can provide it in a protocol extension to URLOpener
:
public extension URLOpener {
func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil) {
open(url, options: options, completionHandler: completion)
}
}
Would allow us to update this and the call to open in performAppSwitch
to:
application.open(appStoreURL) // openVenmoAppPageInAppStore
application.open(appSwitchURL) { success in // performAppSwitch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh this crossed my mind - but I thought the purpose of the protocol extension was confusing to read/deduce. I don't mind the passing of the empty dict and nil completion, but will defer to what folks think is more clear!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the cleaner callsite but I 100% just think that's a personal preference. Lol. I am fine with either so will leave it up to you to decide!
|
||
@objc public override func open(_ URL: URL, completionHandler: (@Sendable (Bool) -> Void)? = nil) { | ||
lastOpenURL = URL | ||
public func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler: ((Bool) -> Void)?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Summary of changes
UIApplication.shared
BTVenmoClient
source code which only existed for mockingFakeApplication
to conform to new protocolReferences
http://swiftyjimmy.com/mock-uiapplication-swift/
Checklist
Added a changelog entryAuthors
@scannillo