Skip to content

Commit

Permalink
Add comments and fix AuthDefaultUIDelegate for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Jul 28, 2023
1 parent c054b81 commit 5119d73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions FirebaseAuth/Sources/Swift/Auth/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,7 @@ extension Auth: AuthInterop {
return
}

// Using reflection here to avoid build errors in extensions.
let sel = NSSelectorFromString("sharedApplication")
guard UIApplication.responds(to: sel),
let application = UIApplication.perform(sel).takeUnretainedValue() as? UIApplication
Expand Down
28 changes: 18 additions & 10 deletions FirebaseAuth/Sources/Swift/Utilities/AuthDefaultUIDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,39 @@

import Foundation
import UIKit
#if COCOAPODS
@_implementationOnly import GoogleUtilities
#else
@_implementationOnly import GoogleUtilities_Environment
#endif

/** @class AuthDefaultUIDelegate
@brief Class responsible for providing a default FIRAuthUIDelegate.
@remarks This class should be used in the case that a UIDelegate was expected and necessary to
continue a given flow, but none was provided.
*/
class AuthDefaultUIDelegate: NSObject, AuthUIDelegate {
// TODO: Figure out what to do for extensions.
/** @fn defaultUIDelegate
@brief Returns a default FIRAuthUIDelegate object.
@return The default FIRAuthUIDelegate object.
*/
@available(iOSApplicationExtension, unavailable)
@available(tvOSApplicationExtension, unavailable)
class func defaultUIDelegate() -> AuthUIDelegate? {
// TODO: Consider removing code below when doing extension testing.
// iOS App extensions should not call [UIApplication sharedApplication], even if UIApplication
// responds to it.
guard let applicationClass = NSClassFromString("UIApplication"),
applicationClass.responds(to: NSSelectorFromString("sharedApplication")) else {
if GULAppEnvironmentUtil.isAppExtension() {
// iOS App extensions should not call [UIApplication sharedApplication], even if
// UIApplication responds to it.
return nil
}

// Using reflection here to avoid build errors in extensions.
let sel = NSSelectorFromString("sharedApplication")
guard UIApplication.responds(to: sel),
let application = UIApplication.perform(sel).takeUnretainedValue() as? UIApplication
else {
return nil
}
var topViewController: UIViewController?
if #available(iOS 13.0, tvOS 13.0, *) {
let connectedScenes = UIApplication.shared.connectedScenes
let connectedScenes = application.connectedScenes
for scene in connectedScenes {
if let windowScene = scene as? UIWindowScene {
for window in windowScene.windows {
Expand All @@ -51,7 +59,7 @@
}
}
} else {
topViewController = UIApplication.shared.keyWindow?.rootViewController
topViewController = application.keyWindow?.rootViewController
}
while true {
if let controller = topViewController?.presentedViewController {
Expand Down
2 changes: 0 additions & 2 deletions FirebaseAuth/Sources/Swift/Utilities/AuthURLPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import WebKit
import SafariServices

// TODO: Remove objc's and publics

/** @class AuthURLPresenter
@brief A Class responsible for presenting URL via SFSafariViewController or WKWebView.
*/
Expand Down

0 comments on commit 5119d73

Please sign in to comment.