capacitor-community / privacy-screen

⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.
MIT License
87 stars 23 forks source link

bug: Application tried to present modally a view controller that is already being presented #56

Closed qliqdev closed 1 year ago

qliqdev commented 1 year ago

Plugin version:

3.0.2

Platform(s):

Current behavior:

Catched 10 times crashes from crashlytics

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                     0xa248 __exceptionPreprocess
1  libobjc.A.dylib                    0x17a68 objc_exception_throw
2  UIKitCore                          0x327fc0 -[UIViewController _presentViewController:withAnimationController:completion:]
3  UIKitCore                          0x39de9c __63-[UIViewController _presentViewController:animated:completion:]_block_invoke_2
4  UIKitCore                          0x316d0 +[UIView(Animation) performWithoutAnimation:]
5  UIKitCore                          0x326f98 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke
6  UIKitCore                          0x3051dc -[UIViewController _performCoordinatedPresentOrDismiss:animated:]
7  UIKitCore                          0xd33f8 -[UIViewController _presentViewController:animated:completion:]
8  UIKitCore                          0xd3234 -[UIViewController presentViewController:animated:completion:]
9  CapacitorCommunityPrivacyScreen    0x5490 (Missing UUID ada146d719f8360f8a0a231b9f880e2d)
10 CapacitorCommunityPrivacyScreen    0x54d4 (Missing UUID ada146d719f8360f8a0a231b9f880e2d)
11 libdispatch.dylib                  0x24b4 _dispatch_call_block_and_release
12 libdispatch.dylib                  0x3fdc _dispatch_client_callout
13 libdispatch.dylib                  0x127f4 _dispatch_main_queue_drain
14 libdispatch.dylib                  0x12444 _dispatch_main_queue_callback_4CF
15 CoreFoundation                     0x9aa08 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
16 CoreFoundation                     0x7c368 __CFRunLoopRun
17 CoreFoundation                     0x811e4 CFRunLoopRunSpecific
18 GraphicsServices                   0x1368 GSEventRunModal
19 UIKitCore                          0x3a2d88 -[UIApplication _run]
20 UIKitCore                          0x3a29ec UIApplicationMain

I gues it is from

@objc func onAppWillResignActive() {
        guard self.isEnabled else {
            return
        }

        DispatchQueue.main.async {
            self.bridge?.viewController?.present(self.privacyViewController!, animated: false, completion: nil)
        }
}

Steps to reproduce:

Related code:

May be we should try

@objc func onAppWillResignActive() {
        guard self.isEnabled else {
            return
        }

        // Check if privacyViewController is already presented
        if self.privacyViewController?.presentingViewController != nil {
              return
        }

        DispatchQueue.main.async {
            self.bridge?.viewController?.present(self.privacyViewController!, animated: false, completion: nil)
        }
}

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 4.7.3
  @capacitor/core: 4.7.3
  @capacitor/android: 4.7.3
  @capacitor/ios: 4.7.3

Installed Dependencies:

  @capacitor/core: 4.7.3
  @capacitor/android: 4.7.3
  @capacitor/cli: 4.7.3
  @capacitor/ios: 4.7.3

[success] iOS looking great! 👌
[success] Android looking great! 👌
robingenz commented 1 year ago

Can you reproduce the issue locally?

qliqdev commented 1 year ago

@robingenz Sure. I'll try. Opened bug so as not to forget to fix it and to consult with you.

github-actions[bot] commented 1 year ago

It looks like there hasn't been a reply in 30 days, so I'm closing this issue.

eric-coker commented 1 year ago

Could the suggested safeguard be included, as it seems harmless enough? I see over 200 instances of the same error in our Crashlytics logs over the past 30 days.