Open cocat00 opened 11 months ago
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let _ = (scene as? UIWindowScene) else { return } print("willConnectTo - screenProtectorKit.configurePreventionScreenshot()") let window = UIWindow(frame: .init(x: 0, y: 100, width: 110, height: 90)) window.windowLevel = .alert + 999 window.isHidden = false let screenProtector = ScreenProtectorKit(window: window) screenProtector.configurePreventionScreenshot() }
My application has multiple Windows, I gave an example, there will be a crash, it seems to be the main thread detection problem, is there a compatible solution?
thread # 1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16f7bbfe0) frame # 0: 0x000000010068d3b8 libMainThreadChecker.dylibtrampoline_c + 4 frame # 1: 0x000000010064d194 libMainThreadChecker.dylibhandler_start + 52 frame # 2: 0x0000000100666fcc libMainThreadChecker.dylib__trampolines + 105992 ... frame #2822: 0x00000001bab15fa4 UIKitCorediscardEngineRecursive + 168 frame #2823: 0x00000001baa80838 UIKitCore-[UIView _layoutConstraintCleanup] + 392 frame #2824: 0x00000001bad04924 UIKitCore-[UIWindow dealloc] + 252 frame #2825: 0x00000001b1a15dd4 libobjc.A.dylibAutoreleasePoolPage::releaseUntil(objc_object**) + 196 frame #2826: 0x00000001b1a197cc libobjc.A.dylibobjc_autoreleasePoolPop + 256 frame #2827: 0x00000001b89ffc38 CoreFoundation_CFAutoreleasePoolPop + 32 frame #2828: 0x00000001b89fd974 CoreFoundationCFRunLoopPerCalloutARPEnd + 48 frame #2829: 0x00000001b89fd518 CoreFoundation`CFRunLoopRun + 2032 frame #2830: 0x00000001b8a0237c CoreFoundationCFRunLoopRunSpecific + 612 frame #2831: 0x00000001f3f2435c GraphicsServicesGSEventRunModal + 164 frame #2832: 0x00000001bad8ef58 UIKitCore-[UIApplication _run] + 888 frame #2833: 0x00000001bad8ebbc UIKitCoreUIApplicationMain + 340 frame #2834: 0x00000001c14200b0 libswiftUIKit.dylibUIKit.UIApplicationMain(Swift.Int32, Swift.Optional<Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>>, Swift.Optional<Swift.String>, Swift.Optional<Swift.String>) -> Swift.Int32 + 104 frame #2835: 0x00000001005510e0 PreventScreenShotstatic UIApplicationDelegate.main() at :0 frame #2836: 0x0000000100551058 PreventScreenShotstatic AppDelegate.$main(self=PreventScreenShot.AppDelegate) at AppDelegate.swift:11:1 frame #2837: 0x00000001005511f4 PreventScreenShotmain at :0 frame #2838: 0x00000001d7f40dec dyld`start + 2220
trampoline_c + 4 frame # 1: 0x000000010064d194 libMainThreadChecker.dylib
__trampolines + 105992 ... frame #2822: 0x00000001bab15fa4 UIKitCore
-[UIView _layoutConstraintCleanup] + 392 frame #2824: 0x00000001bad04924 UIKitCore
AutoreleasePoolPage::releaseUntil(objc_object**) + 196 frame #2826: 0x00000001b1a197cc libobjc.A.dylib
_CFAutoreleasePoolPop + 32 frame #2828: 0x00000001b89fd974 CoreFoundation
CFRunLoopRunSpecific + 612 frame #2831: 0x00000001f3f2435c GraphicsServices
-[UIApplication _run] + 888 frame #2833: 0x00000001bad8ebbc UIKitCore
UIKit.UIApplicationMain(Swift.Int32, Swift.Optional<Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>>, Swift.Optional<Swift.String>, Swift.Optional<Swift.String>) -> Swift.Int32 + 104 frame #2835: 0x00000001005510e0 PreventScreenShot
static AppDelegate.$main(self=PreventScreenShot.AppDelegate) at AppDelegate.swift:11:1 frame #2837: 0x00000001005511f4 PreventScreenShot
My application has multiple Windows, I gave an example, there will be a crash, it seems to be the main thread detection problem, is there a compatible solution?
thread # 1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16f7bbfe0) frame # 0: 0x000000010068d3b8 libMainThreadChecker.dylib:0
frame #2836: 0x0000000100551058 PreventScreenShot:0
frame #2838: 0x00000001d7f40dec dyld`start + 2220
trampoline_c + 4 frame # 1: 0x000000010064d194 libMainThreadChecker.dylib
handler_start + 52 frame # 2: 0x0000000100666fcc libMainThreadChecker.dylib__trampolines + 105992 ... frame #2822: 0x00000001bab15fa4 UIKitCore
discardEngineRecursive + 168 frame #2823: 0x00000001baa80838 UIKitCore-[UIView _layoutConstraintCleanup] + 392 frame #2824: 0x00000001bad04924 UIKitCore
-[UIWindow dealloc] + 252 frame #2825: 0x00000001b1a15dd4 libobjc.A.dylibAutoreleasePoolPage::releaseUntil(objc_object**) + 196 frame #2826: 0x00000001b1a197cc libobjc.A.dylib
objc_autoreleasePoolPop + 256 frame #2827: 0x00000001b89ffc38 CoreFoundation_CFAutoreleasePoolPop + 32 frame #2828: 0x00000001b89fd974 CoreFoundation
CFRunLoopPerCalloutARPEnd + 48 frame #2829: 0x00000001b89fd518 CoreFoundation`CFRunLoopRun + 2032 frame #2830: 0x00000001b8a0237c CoreFoundationCFRunLoopRunSpecific + 612 frame #2831: 0x00000001f3f2435c GraphicsServices
GSEventRunModal + 164 frame #2832: 0x00000001bad8ef58 UIKitCore-[UIApplication _run] + 888 frame #2833: 0x00000001bad8ebbc UIKitCore
UIApplicationMain + 340 frame #2834: 0x00000001c14200b0 libswiftUIKit.dylibUIKit.UIApplicationMain(Swift.Int32, Swift.Optional<Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>>, Swift.Optional<Swift.String>, Swift.Optional<Swift.String>) -> Swift.Int32 + 104 frame #2835: 0x00000001005510e0 PreventScreenShot
static UIApplicationDelegate.main() atstatic AppDelegate.$main(self=PreventScreenShot.AppDelegate) at AppDelegate.swift:11:1 frame #2837: 0x00000001005511f4 PreventScreenShot
main at