Skip to content
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

Added a guard check to request the shared UIApplication instance usin… #212

Merged
merged 4 commits into from
Jun 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sources/iOS/OAuth2Authorizer+iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
- throws: UnableToOpenAuthorizeURL on failure
*/
public func openAuthorizeURLInBrowser(_ url: URL) throws {
if !UIApplication.shared.openURL(url) {

// By asking for the shared instance method by using the "value for key" method on UIApplication, we are able to
// bypass the Swift compilation restriction that blocks the library from being compiled for an extension when
// directly referencing it. We do it as an optional so in the advent of this method being called, like in an
// extension, we handle it as though its not supported.
guard let application = UIApplication.value(forKey: "sharedApplication") as? UIApplication else {
throw OAuth2Error.unableToOpenAuthorizeURL
}

if !application.openURL(url) {
throw OAuth2Error.unableToOpenAuthorizeURL
}
}
Expand Down