Skip to content

bug: Application tried to present modally a view controller <UIViewController: 0x10392e710> that is already being presented by <Capacitor.CAPBridgeViewController: 0x10390bf60> #102

@yogo10803

Description

@yogo10803

Plugin version:

5.1.2

Platform(s):

iOS

Current behavior:

App crashed after pulling down the notification bar from the top left corner of the phone.

Steps to reproduce:

Pull down the notification bar from the top left corner of the phone in the app page which enabled privacy screen.
Maybe the issue is same as https://github.com/capacitor-community/privacy-screen/issues/83#issue-2002693363

Related code:

@objc public func handleWillResignActiveNotification() {
        guard self.isEnabled else {
            return
        }
        DispatchQueue.main.async {
            let window = UIApplication.shared.connectedScenes
                .filter({$0.activationState == .foregroundActive || $0.activationState == .foregroundInactive})
                .compactMap({$0 as? UIWindowScene}).first?.windows.filter({$0.isKeyWindow}).first
            if var rootVC = window?.rootViewController {
                while let topVC = rootVC.presentedViewController {
                    rootVC = topVC
                }
                if rootVC.presentedViewController != self.privacyViewController {
                    rootVC.present(self.privacyViewController, animated: false, completion: nil)
                }
            } else {
                if self.plugin.bridge?.viewController?.presentedViewController != self.privacyViewController {
                    self.plugin.bridge?.viewController?.present(self.privacyViewController, animated: false, completion: nil)
                }
            }
        }
    }

The both version below are my adjustment, which solve the issue. Please check which adjustment is more appropriate and update it to the new version. Thanks a lot !!!

@objc public func handleWillResignActiveNotification() {
        guard self.isEnabled else {
            return
        }
        DispatchQueue.main.async {
            // ***  here
            guard self.privacyViewController.isBeingPresented else {
                return
            }
            let window = UIApplication.shared.connectedScenes
                .filter({$0.activationState == .foregroundActive || $0.activationState == .foregroundInactive})
                .compactMap({$0 as? UIWindowScene}).first?.windows.filter({$0.isKeyWindow}).first
            if var rootVC = window?.rootViewController {
                while let topVC = rootVC.presentedViewController {
                    rootVC = topVC
                }
                if rootVC.presentedViewController != self.privacyViewController {
                    rootVC.present(self.privacyViewController, animated: false, completion: nil)
                }
            } else {
                if self.plugin.bridge?.viewController?.presentedViewController != self.privacyViewController {
                    self.plugin.bridge?.viewController?.present(self.privacyViewController, animated: false, completion: nil)
                }
            }
        }
    }
@objc public func handleWillResignActiveNotification() {
        guard self.isEnabled else {
            return
        }
        DispatchQueue.main.async {
            let window = UIApplication.shared.connectedScenes
                .filter({$0.activationState == .foregroundActive || $0.activationState == .foregroundInactive})
                .compactMap({$0 as? UIWindowScene}).first?.windows.filter({$0.isKeyWindow}).first
            // *** here, add !self.privacyViewController.isBeingPresented
            if var rootVC = window?.rootViewController, !self.privacyViewController.isBeingPresented {
                while let topVC = rootVC.presentedViewController {
                    rootVC = topVC
                }
                if rootVC.presentedViewController != self.privacyViewController {
                    rootVC.present(self.privacyViewController, animated: false, completion: nil)
                }
            } else {
                if self.plugin.bridge?.viewController?.presentedViewController != self.privacyViewController {
                    self.plugin.bridge?.viewController?.present(self.privacyViewController, animated: false, completion: nil)
                }
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions