Closed iLiuChang closed 1 year ago
private func setupCamera() { guard let backCamera = getCamera(position: .back) else { return } guard let input = try? AVCaptureDeviceInput(device: backCamera) else { return }
如果此代码执行了return, 此时movieFileOutput和imageOutput为空, 强制解包会造成闪退
movieFileOutput
imageOutput
Thread 0 name: Thread 0 Crashed: 0 MIGO Live 0x0000000103336934 Swift runtime failure: Unexpectedly found nil while implicitly unwrapping an Optional value + 0 (ZLCustomCamera.swift:0) 1 MIGO Live 0x0000000103336934 ZLCustomCamera.takePicture() + 740 (ZLCustomCamera.swift:752) 2 MIGO Live 0x0000000103336680 ZLCustomCamera.takePicture() + 48 (ZLCustomCamera.swift:748) 3 MIGO Live 0x000000010333697c @objc ZLCustomCamera.takePicture() + 28 (<compiler-generated>:0) 4 UIKitCore 0x000000018b297470 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 128 (UIPerformVoidSelector.h:48) 5 UIKitCore 0x000000018b6050bc _UIGestureRecognizerSendTargetActions + 92 (UIGestureRecognizer.m:1527) 6 UIKitCore 0x000000018b37ec30 _UIGestureRecognizerSendActions + 272 (UIGestureRecognizer.m:1566) 7 UIKitCore 0x000000018b25f60c -[UIGestureRecognizer _updateGestureForActiveEvents] + 484 (UIGestureRecognizer.m:0) 8 UIKitCore 0x000000018b30b560 _UIGestureEnvironmentUpdate + 2436 (UIGestureEnvironment.m:198) 9 UIKitCore 0x000000018bb9293c -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 288 (UIGestureEnvironment.m:1376) 10 UIKitCore 0x000000018b2d0020 -[UIGestureEnvironment _updateForEvent:window:] + 188 (UIGestureEnvironment.m:1345) 11 UIKitCore 0x000000018b2d4978 -[UIWindow sendEvent:] + 3268 (UIWindow.m:3472) 12 UIKitCore 0x000000018b2d3c48 -[UIApplication sendEvent:] + 672 (UIApplication.m:12548) 13 UIKitCore 0x000000018b2d3304 __dispatchPreprocessedEventFromEventQueue + 7084 (UIEventDispatcher.m:2417) 14 UIKitCore 0x000000018b31b018 __processEventQueue + 5632 (UIEventDispatcher.m:2726) 15 UIKitCore 0x000000018b62355c __eventFetcherSourceCallback + 224 (UIEventDispatcher.m:2798) 16 CoreFoundation 0x00000001890d9f34 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1957) 17 CoreFoundation 0x00000001890e630c __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2001) 18 CoreFoundation 0x000000018906a1d0 __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2038) 19 CoreFoundation 0x000000018907fb8c __CFRunLoopRun + 836 (CFRunLoop.c:2953) 20 CoreFoundation 0x0000000189084ec0 CFRunLoopRunSpecific + 612 (CFRunLoop.c:3418) 21 GraphicsServices 0x00000001c30db368 GSEventRunModal + 164 (GSEvent.c:2196) 22 UIKitCore 0x000000018b57a86c -[UIApplication _run] + 888 (UIApplication.m:3754) 23 UIKitCore 0x000000018b57a4d0 UIApplicationMain + 340 (UIApplication.m:5344) 24 MIGO Live 0x00000001028c94b4 main + 80 (main.m:14) 25 dyld 0x00000001a78a6960 start + 2528 (dyldMain.cpp:1170)
如果此代码执行了return, 此时
movieFileOutput
和imageOutput
为空, 强制解包会造成闪退