5
3

More than 5 years have passed since last update.

ipadでcapturePhoto時にcrashする問題の解決

Last updated at Posted at 2019-02-09

背景

今回初めてアプリ申請した際にrejectの洗礼を受けてしまったので記事にしてみたいと思います。

reject内容

Your app crashed on iPad running iOS 12.1.3 on WiFi when we tapped to take a photo.
自分はipadPro(10.5inch)とiphoneXS Maxとiphone6sを所持していてそれらで実機テストしているのですがipadないので早速困りました笑
幸いcrashlogの方が送られてきていたので以下の記事を参考させてもらいに解析しました
https://qiita.com/ruwatana/items/cc470eb229d267d693b0

crashlog
Last Exception Backtrace:
0   CoreFoundation                  0x1a2ae9ea4 __exceptionPreprocess + 228
1   libobjc.A.dylib                 0x1a1cb9a50 objc_exception_throw + 55
2   AVFoundation                    0x1a8c82b48 -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] + 751
3   camera                          0x1041f4120 0x1041ec000 + 33056

やはりAVCaputurePhotoOutputが怪しい事が分かったので調べると以下の記事を発見https://qiita.com/jumperson/items/1f47e91f2fec80654b09
どうやらiPadではFlashが使えずAVCapturePhotoSettingsのflashModeをautoにしていたらcrashしてしまうとのこと。

解決方法

カメラ起動時にFlashをサポートしていない端末の場合はFlashをoffにすることで解決

viewDidLoad()
//flashサポートしてるかの確認
        let device = AVCaptureDevice.default(
            AVCaptureDevice.DeviceType.builtInWideAngleCamera,
            for: AVMediaType.video, // ビデオ入力
            position: AVCaptureDevice.Position.back)
        if !device!.hasFlash{
            let captureSetting = AVCapturePhotoSettings()
            captureSetting.flashMode = .off
        }

審査通るといいですがまた別の問題でrejectくらいそうです笑

5
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3