pkluz / PKHUD

A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8.
MIT License
3.79k stars 494 forks source link

PKHUD.show(onView:) is crashing with iOS 15 #283

Open arsalangolestanekh opened 2 years ago

arsalangolestanekh commented 2 years ago

Did anybody observed crash with PKHUD.show(onView:) on iOS 15?

Can someone recommend something to resolve this crash

Crashlogs:

`Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000010264298c Exception Note: EXC_CORPSE_NOTIFY Termination Reason: SIGNAL; [5] Terminating Process: exc handler [815]

Terminating Process: exc handler [815] Triggered by Thread: 0

Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 PKHUD 0x10264298c PKHUD.show(onView:) + 956 1 PKHUD 0x102642678 PKHUD.show(onView:) + 168 2 PKHUD 0x102640b54 static HUD.show(_:onView:) + 144 3 my_App 0x1016cb304 0x100dd8000 + 9384708 4 my_App 0x101528d48 0x100dd8000 + 7671112 5 my_App 0x101526658 0x100dd8000 + 7661144 6 my_App 0x101525d28 0x100dd8000 + 7658792 7 my_App 0x1013d7c40 0x100dd8000 + 6290496 8 my_App 0x101581b30 0x100dd8000 + 8035120 9 my_App 0x101581c7c 0x100dd8000 + 8035452 10 IntuneMAMSwift 0x108eb1664 0x108c90000 + 2233956 11 IntuneMAMSwift 0x108ca4c10 0x108c90000 + 85008 12 IntuneMAMSwift 0x108e390f0 0x108c90000 + 1741040 13 IntuneMAMSwift 0x108e38de4 0x108c90000 + 1740260 14 IntuneMAMSwift 0x108e39a24 0x108c90000 + 1743396 15 IntuneMAMSwift 0x108eae9d8 0x108c90000 + 2222552 16 IntuneMAMSwift 0x108eb0ab0 0x108c90000 + 2230960 17 ADAL 0x101dade24 swizzle_ApplicationOpenURLiOS9 + 300 18 UIKitCore 0x18370881c 58-[UIApplication _applicationOpenURLAction:payload:origin:]_block_invoke + 804 19 UIKitCore 0x1835ea1d0 -[UIApplication _applicationOpenURLAction:payload:origin:] + 892 20 UIKitCore 0x1835c58c4 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 5040 21 UIKitCore 0x183566d50 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 496 22 UIKitCore 0x1835aa524 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 288 23 UIKitCore 0x183534370 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 492 24 FrontBoardServices 0x192a54100 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 528 25 FrontBoardServices 0x192a6cd4c 94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152 26 FrontBoardServices 0x192a516b4 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240 27 FrontBoardServices 0x192a57b10 94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 396 28 libdispatch.dylib 0x180beb660 _dispatch_client_callout + 20 29 libdispatch.dylib 0x180bef118 _dispatch_block_invoke_direct + 264 30 FrontBoardServices 0x192a52f94 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 48 31 FrontBoardServices 0x192a523d4 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220 32 FrontBoardServices 0x192a569e4 -[FBSSerialQueue _performNextFromRunLoopSource] + 28 33 CoreFoundation 0x180f9b020 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 34 CoreFoundation 0x180fabce0 CFRunLoopDoSource0 + 208 35 CoreFoundation 0x180ee5fe8 CFRunLoopDoSources0 + 268 36 CoreFoundation 0x180eeb7f4 __CFRunLoopRun + 820 37 CoreFoundation 0x180eff3b8 CFRunLoopRunSpecific + 600 38 GraphicsServices 0x19c88f38c GSEventRunModal + 164 39 UIKitCore 0x18389f6a8 -[UIApplication run] + 1100 40 UIKitCore 0x18361e7f4 UIApplicationMain + 2092 41 IntuneMAMSwiftStub 0x108c7a1a8 cmarRealUIApplicationMain(::::) + 96 42 IntuneMAMSwift 0x108f17294 cmarHookedUIApplicationMain(:::_:) + 216 43 securelinegen2_intune 0x100eac808 0x100dd8000 + 870408 44 dyld 0x101d05a24 start + 520 `

tthejus commented 2 years ago

Me too

MarkerwApk commented 2 years ago

Info from Crashlytics image image

arsalangolestanekh commented 2 years ago

Do you know the way how to fix those crashes?

MarkerwApk commented 2 years ago

No :( I can't reproduce in debug. I have only reports from users. You pass onView parameter?

arsalangolestanekh commented 2 years ago

I think it is an answer, I think we should pass view

MarkerwApk commented 2 years ago

Ok, I thing it'a issue, when you don't pass view. HUD use keyWindow. Changes for iOS 15: https://developer.apple.com/documentation/uikit/uiwindow/1621612-keywindow

It's a fork with commit for this issue: https://github.com/kevin-zqw/PKHUD/commit/597e6601dfc441d6b715e9b52520560ff435ef1c

arsalangolestanekh commented 2 years ago

Wow, @MarkerwApk when was it fix?

do we have this change in the latest version?

MarkerwApk commented 2 years ago

I thing no. I will try pass UIView and I will be observe Crashlytics.

AlexNsbmr commented 2 years ago

@MarkerwApk did you make a pull request to the main repo? Sounds like it's a easy fix

MarkerwApk commented 2 years ago

I don't change library. I only, change my local code: from: image

to: image

abmomen commented 2 years ago

I am also getting crash on this method when I change the scheme and run the project without running a clean build. If I clean and build again then it does not crash anymore.

raphaels17 commented 2 years ago

yes i know how to fix it, however I dont know how to contribute to the improvemnet

this should will fix it

var window = UIApplication.shared.keyWindow //--> nil = crash if #available(iOS 13.0, *) { window = UIApplication.shared.connectedScenes .filter({$0.activationState == .foregroundActive}) .compactMap({$0 as? UIWindowScene}) .first?.windows .filter({$0.isKeyWindow}).first }

realchema commented 2 years ago

Has anyone managed to fix the problem? I’m experiencing the same issue from iOS 15.4 and 15.5

MarkerwApk commented 2 years ago

Has anyone managed to fix the problem? I’m experiencing the same issue from iOS 15.4 and 15.5

https://github.com/pkluz/PKHUD/issues/283#issuecomment-992221378

rferbesa commented 2 years ago

I've been experienced this problem since a couple of months ago when the user opens a deep link (the HUD is shown) and the app is not ready yet. After trying several things I finally tried this, thinking it would be the ultimate solution:

            if UIApplication.shared.keyWindow != nil {
                HUD.show(.progress)
            }

But I'm still receiving crashes in this line (HUD.show(.progress))! Why?? It has no sense to me. Anyway I'm going to test @MarkerwApk and add onView: view to the call and see what it happens.

MarkerwApk commented 2 years ago

I've been experienced this problem since a couple of months ago when the user opens a deep link (the HUD is shown) and the app is not ready yet. After trying several things I finally tried this, thinking it would be the ultimate solution:

            if UIApplication.shared.keyWindow != nil {
                HUD.show(.progress)
            }

But I'm still receiving crashes in this line (HUD.show(.progress))! Why?? It has no sense to me. Anyway I'm going to test @MarkerwApk and add onView: view to the call and see what it happens.

Look at documentation: https://developer.apple.com/documentation/uikit/uiwindow/1621612-keywindow It's very bad from Apple side(change behavior and implementation). "onView" should resolve issue.

rferbesa commented 2 years ago

Thanks!! I'm gonna try your solution.

rferbesa commented 2 years ago

In my case I'm still having issues with the deep linking, I'm pretty sure this is because the view is not ready yet, so I'm trying:

            let isViewVisible = self.viewIfLoaded?.window != nil
            if isViewVisible {
               HUD.show(.progress, onView: self.view)
            }
rferbesa commented 2 years ago

Well, I'm still having crashes with this last code...I'll find another option.

realchema commented 2 years ago

@rferbesa try this let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first

pass the variable to onView and let me know

rferbesa commented 2 years ago

Thanks! I'll try that and let you know.

rferbesa commented 2 years ago

It didn't work. I think is a problem of how my app detects if it's in background or not (or if the view is being shown or not). I won't show the spinner in the deep linking flow to "fix" this.