ios - AVCapturePhotoOutput 崩溃

标签 ios swift avcapturesession avcapturephotooutput

我的应用程序因崩溃而被拒绝。我无法在本地重现崩溃,但由于 Apple 提供的崩溃日志,我能够将有问题的代码缩小到以下范围:

func capturePhoto() {
    let photoOutputSettings = AVCapturePhotoSettings()
    photoOutputSettings.flashMode = Settings.shared.flash
    photoOutputSettings.isAutoStillImageStabilizationEnabled = true
    photoOutputSettings.isHighResolutionPhotoEnabled = true

    self.photoOutput.capturePhoto(with: photoOutputSettings, delegate: self) //crash
}

此外,审阅者提到他们正在运行 iOS 11.3.1 的 iPad 上进行测试。以下是崩溃日志的相关部分:

{"app_name":"xxxxx","timestamp":"2018-05-07 15:19:10.13 -0700","app_version":"1.0","slice_uuid":"059c64b6-ea13-3bca-97c0-e05dd5eed102","adam_id":1341531999,"build_version":"7","bundleID":"xxxxx","share_with_app_devs":false,"is_first_party":false,"bug_type":"109","os_version":"iPhone OS 11.3.1 (15E302)","incident_id":"4B4E6531-6F8E-4F2A-B262-94685C5FF287","name":"xxxxx"}
Incident Identifier: 4B4E6531-6F8E-4F2A-B262-94685C5FF287
CrashReporter Key:   357841d912f2df927b24861ec18fb870765ae9bd
Hardware Model:      xxx1
Process:             xxxxx [1938]
Path:                /private/var/containers/Bundle/Application/40DDE031-CEDC-4197-989C-C3DEA953492F/xxxxx.app/xxxxx
Identifier:          xxxxx
Version:             7 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           xxxxx [1139]


Date/Time:           2018-05-07 15:19:09.9972 -0700
Launch Time:         2018-05-07 15:19:07.3874 -0700
OS Version:          iPhone OS 11.3.1 (15E302)
Baseband Version:    n/a
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
abort() called

Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                  0x183d42d8c __exceptionPreprocess + 228
1   libobjc.A.dylib                 0x182efc5ec objc_exception_throw + 55
2   AVFoundation                    0x1898cadc4 -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] + 811
3   QuickRecord                     0x10498e4b0 specialized MainViewController.capturePhotoButtonTapped(_:) + 74928 (MainViewController.swift:210)
4   QuickRecord                     0x10498be34 @objc MainViewController.capturePhotoButtonTapped(_:) + 65076 (MainViewController.swift:187)
5   UIKit                           0x18da726c8 -[UIApplication sendAction:to:from:forEvent:] + 95
6   UIKit                           0x18db938a4 -[UIControl sendAction:to:forEvent:] + 79
7   UIKit                           0x18da7877c -[UIControl _sendActionsForEvents:withEvent:] + 439
8   UIKit                           0x18dbae1dc -[UIControl touchesEnded:withEvent:] + 571
9   QuickRecord                     0x104989c28 specialized TouchAnimationButton.touchesEnded(_:with:) + 56360 (TouchAnimationButton.swift:64)
10  QuickRecord                     0x104988c7c @objc TouchAnimationButton.touchesBegan+ 52348 (_:with:) + 139
11  UIKit                           0x18daf5a48 -[UIWindow _sendTouchesForEvent:] + 2427
12  UIKit                           0x18daea8f8 -[UIWindow sendEvent:] + 3159
13  UIKit                           0x18dae9238 -[UIApplication sendEvent:] + 339
14  UIKit                           0x18e2cac0c __dispatchPreprocessedEventFromEventQueue + 2339
15  UIKit                           0x18e2cd1b8 __handleEventQueueInternal + 4743
16  UIKit                           0x18e2c6258 __handleHIDEventFetcherDrain + 151
17  CoreFoundation                  0x183ceb404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 23
18  CoreFoundation                  0x183ceac2c __CFRunLoopDoSources0 + 275
19  CoreFoundation                  0x183ce879c __CFRunLoopRun + 1203
20  CoreFoundation                  0x183c08da8 CFRunLoopRunSpecific + 551
21  GraphicsServices                0x185beb020 GSEventRunModal + 99
22  UIKit                           0x18dbe978c UIApplicationMain + 235
23  QuickRecord                     0x104982de0 main + 28128 (PermissionsViewController.swift:14)
24  libdyld.dylib                   0x183699fc0 start + 3


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001837c92ec __pthread_kill + 8
1   libsystem_pthread.dylib         0x000000018396a288 pthread_kill$VARIANT$mp + 376
2   libsystem_c.dylib               0x0000000183737d0c abort + 140
3   libc++abi.dylib                 0x0000000182ed22c8 __cxa_bad_cast + 0
4   libc++abi.dylib                 0x0000000182ed2470 default_unexpected_handler+ 5232 () + 0
5   libobjc.A.dylib                 0x0000000182efc8d4 _objc_terminate+ 35028 () + 124
6   libc++abi.dylib                 0x0000000182eec37c std::__terminate(void (*)+ 111484 ()) + 16
7   libc++abi.dylib                 0x0000000182eebf78 __cxa_rethrow + 144
8   libobjc.A.dylib                 0x0000000182efc7ac objc_exception_rethrow + 44
9   CoreFoundation                  0x0000000183c08e18 CFRunLoopRunSpecific + 664
10  GraphicsServices                0x0000000185beb020 GSEventRunModal + 100
11  UIKit                           0x000000018dbe978c UIApplicationMain + 236
12  QuickRecord                     0x0000000104982de0 main + 28128 (PermissionsViewController.swift:14)
13  libdyld.dylib                   0x0000000183699fc0 start + 4

知道什么可能导致这次崩溃吗? iPad 上处理 flashMode 的方式可能有问题吗?如果是这样,为什么崩溃报告没有像其他 SO 帖子中那样提到闪存是一个问题?如有任何帮助,我们将不胜感激。

最佳答案

这绝对是闪光模式。如果您使用的相机没有闪光灯(例如 iPad 相机),当您调用 capturePhoto 并向其传递 .off 以外的参数时,您的应用将会崩溃闪光模式。

要检查相机是否有闪光灯,请使用该相机上的 AVCaptureDevice.hasFlash 属性。

关于ios - AVCapturePhotoOutput 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50224497/

相关文章:

swift - 使用 AVCaptureVideoDataOutput 正确录制视频

ios - 请求非结构或联合 :error 中的成员 "nameField"

ios - 在 Visual Studio Tools for Apache Cordova 上设置 iPhone 6 启动图像

ios - 无法在 iOS Swift 中导入 UserNotifications

ios - AVPlayer 不播放 URL 声音 Swift 3

ios - 如何将 AVCaptureSession.sessionPreset 为 720x1280px(或任何 1/1.77 比例)

ios - 如何在 iOS 上将编码的 CMSampleBuffer 样本保存到 mp4 文件

ios - Container View 及其 subview 的大小相同

iphone - 如果单元格是第一个响应者并且不在屏幕上,则不会调用UITableViewCell setEditing:animated

ios - 获取 token 和用户信息 iOS Swift