-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Labels
Description
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)
}
}
}
}
Reactions are currently unavailable