仅在 iPhone XR 上打开相机拍摄视频时应用程序崩溃
Application crashing when opening camera to capture video only on iPhone XR
我仅在 iPhone XR 上收到以下崩溃和错误消息。
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'
CoreFoundation 0x00000002038d23a8 __exceptionPreprocess + 232
1 libobjc.A.dylib 0x0000000202ad7d00 objc_exception_throw + 56
2 AVFoundation 0x0000000209950220 __47-[AVCaptureFigVideoDevice setActiveColorSpace:]_block_invoke + 204
3 libdispatch.dylib 0x00000002032e1884 _dispatch_client_callout + 16
4 libdispatch.dylib 0x00000002032ee404 _dispatch_lane_barrier_sync_invoke_and_complete + 56
5 AVFoundation 0x00000002099500e4 -[AVCaptureFigVideoDevice setActiveColorSpace:] + 132
6 Foundation 0x000000020433247c ___NSSetLongLongValueAndNotify_block_invoke + 44
7 Foundation 0x00000002043360f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 608
8 Foundation 0x0000000204283688 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
9 Foundation 0x0000000204331860 _NSSetLongLongValueAndNotify + 280
10 AVFoundation 0x000000020996c808 -[AVCaptureSession _updateDeviceActiveFormatsAndActiveConnections] + 5064
11 AVFoundation 0x000000020996acac -[AVCaptureSession _buildAndRunGraph] + 104
12 AVFoundation 0x0000000209964ce4 -[AVCaptureSession _commitConfiguration] + 108
13 Foundation 0x0000000204332208 ___NSSetObjectValueAndNotify_block_invoke + 44
14 Foundation 0x00000002043360f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 608
15 Foundation 0x0000000204283688 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
16 Foundation 0x0000000204330b8c _NSSetObjectValueAndNotify + 280
17 CameraUI 0x00000002207ba3a0 -[CAMModeAndDeviceCommand executeWithContext:] + 668
18 CameraUI 0x00000002207b9a74 -[CAMCaptureEngine _executeCommand:withContext:] + 212
19 CameraUI 0x00000002207b9b2c -[CAMCaptureEngine _executeCommand:withContext:] + 396
20 CameraUI 0x00000002207b9528 __35-[CAMCaptureEngine enqueueCommand:]_block_invoke + 104
错误消息说:
-[AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'
您正在尝试传递一个不可用的值。根据苹果文档,并非所有设备都具有相同的可用色彩空间列表。 https://developer.apple.com/documentation/avfoundation/avcapturedevice/1648668-activecolorspace
这就是为什么它只在你提到的 XR 上失败。
在尝试设置之前,您需要使用 activeFormat.supportedColorSpaces
检查当前设备支持哪些值。
如果您尝试通过在您的应用程序中配置 AVCaptureSession 来 运行 相机会话,它会根据设备格式支持的 ColorSpaces 和当前 AVCaptureSession 拓扑自动调整 AVCaptureDevice 的 activeFormat 和 activeColorSpace 属性。尝试将 class AVCaptureSession 的 属性 "automaticallyConfiguresCaptureDeviceForWideColor" 设置为 false。
captureSessionInstance.automaticallyConfiguresCaptureDeviceForWideColor = false
当您不在该视图中时也停止 运行ning 捕获会话,并在需要时重新启动。
captureSessionInstance.stopRunning()
captureSessionInstance.startRunning()
我仅在 iPhone XR 上收到以下崩溃和错误消息。
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'
CoreFoundation 0x00000002038d23a8 __exceptionPreprocess + 232
1 libobjc.A.dylib 0x0000000202ad7d00 objc_exception_throw + 56
2 AVFoundation 0x0000000209950220 __47-[AVCaptureFigVideoDevice setActiveColorSpace:]_block_invoke + 204
3 libdispatch.dylib 0x00000002032e1884 _dispatch_client_callout + 16
4 libdispatch.dylib 0x00000002032ee404 _dispatch_lane_barrier_sync_invoke_and_complete + 56
5 AVFoundation 0x00000002099500e4 -[AVCaptureFigVideoDevice setActiveColorSpace:] + 132
6 Foundation 0x000000020433247c ___NSSetLongLongValueAndNotify_block_invoke + 44
7 Foundation 0x00000002043360f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 608
8 Foundation 0x0000000204283688 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
9 Foundation 0x0000000204331860 _NSSetLongLongValueAndNotify + 280
10 AVFoundation 0x000000020996c808 -[AVCaptureSession _updateDeviceActiveFormatsAndActiveConnections] + 5064
11 AVFoundation 0x000000020996acac -[AVCaptureSession _buildAndRunGraph] + 104
12 AVFoundation 0x0000000209964ce4 -[AVCaptureSession _commitConfiguration] + 108
13 Foundation 0x0000000204332208 ___NSSetObjectValueAndNotify_block_invoke + 44
14 Foundation 0x00000002043360f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 608
15 Foundation 0x0000000204283688 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
16 Foundation 0x0000000204330b8c _NSSetObjectValueAndNotify + 280
17 CameraUI 0x00000002207ba3a0 -[CAMModeAndDeviceCommand executeWithContext:] + 668
18 CameraUI 0x00000002207b9a74 -[CAMCaptureEngine _executeCommand:withContext:] + 212
19 CameraUI 0x00000002207b9b2c -[CAMCaptureEngine _executeCommand:withContext:] + 396
20 CameraUI 0x00000002207b9528 __35-[CAMCaptureEngine enqueueCommand:]_block_invoke + 104
错误消息说:
-[AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'
您正在尝试传递一个不可用的值。根据苹果文档,并非所有设备都具有相同的可用色彩空间列表。 https://developer.apple.com/documentation/avfoundation/avcapturedevice/1648668-activecolorspace
这就是为什么它只在你提到的 XR 上失败。
在尝试设置之前,您需要使用 activeFormat.supportedColorSpaces
检查当前设备支持哪些值。
如果您尝试通过在您的应用程序中配置 AVCaptureSession 来 运行 相机会话,它会根据设备格式支持的 ColorSpaces 和当前 AVCaptureSession 拓扑自动调整 AVCaptureDevice 的 activeFormat 和 activeColorSpace 属性。尝试将 class AVCaptureSession 的 属性 "automaticallyConfiguresCaptureDeviceForWideColor" 设置为 false。
captureSessionInstance.automaticallyConfiguresCaptureDeviceForWideColor = false
当您不在该视图中时也停止 运行ning 捕获会话,并在需要时重新启动。
captureSessionInstance.stopRunning()
captureSessionInstance.startRunning()