Tuesday, October 20, 2026
HomeiOS Developmentios - MSAL signout error: ParentViewController has no window

ios – MSAL signout error: ParentViewController has no window

[ad_1]

I’ve an app with a HomeViewController inside a navigation controller. When a button is tapped I do a pushViewController for MSAL to register and whether or not profitable or not I do one other pushViewController to point out outcomes.

This third view has a signout button that does a popViewController from a protocol and calls MSAL signout methodology. The register is working completely, I get a profitable callback with token and all the things. However after I go to signout utilizing the identical webviewParameters, I get an error. I can PO my account information and webviewParameters and the parentViewController is legitimate and set to what it is speculated to be however I am unsure the way to repair “parentViewController has no window!”. I adopted the iOS instance discovered of their web site, so I will not publish that code except it is completely different.

btw – utilizing 3 VC’s are my necessities for a PoC.

hope this is sensible.

in HomeViewController:

let storyboard = UIStoryboard(title: "Fundamental", bundle: nil)
    guard let login = storyboard.instantiateViewController(identifier: MSALViewController.className) as? MSALViewController else {
        return
    }
    
    self.navigationController?.pushViewController(login, animated: true)

in MSALViewController

func initWebViewParams() {
    viewModel.webViewParameters = MSALWebviewParameters(authPresentationViewController: self)
}

... different config stuff -> register (working)

// delegate strategies
func didSignOutOfMSAL() {
    DispatchQueue.principal.async { [weak self] in
        guard let self = self else { return }
        // pop from third view
        self.navigationController?.popViewController(animated: true)
        
        self.viewModel.signOut {success in
            self.navigationController?.popToRootViewController(animated: true)
        } onError: { message in
            self.showAlert(withMessage: message)
        }
    }
}

in MSALViewModel:

func signOut(onSuccess: @escaping (Bool) -> Void, onError: @escaping (String) -> Void) {
    
    guard let applicationContext = self.applicationContext else { return }
    guard let webViewParameters = self.webViewParameters else { return }
    guard let account = self.currentAccount else { return }
    
    do {
        
        /**
         Removes all tokens from the cache for this utility for the offered account
         
         - account:    The account to take away from the cache
         */
        
        let signoutParameters = MSALSignoutParameters(webviewParameters: webViewParameters)
        signoutParameters.signoutFromBrowser = false
        
        applicationContext.signout(with: account, signoutParameters: signoutParameters, completionBlock: {(success, error) in
            
            if let mother or father = signoutParameters.webviewParameters.parentViewController {
                print("*** mother or father okay: (mother or father)")
            } else {
                print("*** ERROR:: mother or father not discovered")
            }
            
            if let error = error {
                print("Could not signal out account with error: (error)")
                onError(error.localizedDescription)
                return
            }
            
            print("Signal out accomplished efficiently")
            self.accessToken = ""
            self.updateCurrentAccount(account: nil)
            onSuccess(true)
        })
    }
}

print: *** mother or father okay: <LKEMSALPOC_iOS.MSALViewController: 0x7fb1c4705b90>

print: Could not signal out account with error: Error Area=MSALErrorDomain Code=-50000 “(null)” UserInfo={MSALErrorDescriptionKey=parentViewController has no window! Present a sound controller with view and window., MSALInternalErrorCodeKey=-42000, MSALCorrelationIDKey=6B48BC4C-1327-4181-9302-3CB74191E2E8}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments