Skip to content

Commit

Permalink
Merge pull request #46 from frontegg/FR-16603-fix-handle-open-url
Browse files Browse the repository at this point in the history
FR-16603 - Add support to handle open url with rootVC for flutter
  • Loading branch information
frontegg-david committed Jun 23, 2024
2 parents 43d2554 + aa9f108 commit de9ee1a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Sources/FronteggSwift/FronteggAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,21 @@ public class FronteggAuth: ObservableObject {

}

internal func getRootVC() -> UIViewController? {
internal func getRootVC(_ useAppRootVC: Bool = false) -> UIViewController? {


if let appDelegate = UIApplication.shared.delegate,
let window = appDelegate.window,
let rootVC = window?.rootViewController {
if let presented = rootVC.presentedViewController {
return presented
}else {

if(useAppRootVC){
return rootVC
}else {
if let presented = rootVC.presentedViewController {
return presented
}else {
return rootVC
}
}
}

Expand Down Expand Up @@ -505,20 +510,22 @@ public class FronteggAuth: ObservableObject {
exit(500)
}
}
public func handleOpenUrl(_ url: URL) -> Bool {
public func handleOpenUrl(_ url: URL, _ useAppRootVC: Bool = false) -> Bool {

if(!url.absoluteString.hasPrefix(self.baseUrl)){
self.appLink = false
return false
}

guard let rootVC = self.getRootVC(useAppRootVC) else {
logger.error(FronteggError.authError("Unable to find root viewController").localizedDescription)
return false;
}

if(self.embeddedMode){
self.pendingAppLink = url
self.webLoading = true
guard let rootVC = self.getRootVC() else {
logger.error(FronteggError.authError("Unable to find root viewController").localizedDescription)
return false;
}


let loginModal = EmbeddedLoginModal(parentVC: rootVC)
let hostingController = UIHostingController(rootView: loginModal)
Expand Down

0 comments on commit de9ee1a

Please sign in to comment.