AVCaptureDevice.requestAccess() crash
Asked Answered
W

2

5

I created an iOS single view application using Swift 3.0 and Xcode 8 Beta 2. I am linking with the AVFoundation.framework.

This is my view controller code:

import UIKit
import AVFoundation

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == .notDetermined {
      AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted: Bool) in
        if granted {
          print("granted")
        }
        else {
          print("not granted")
        }
      })
    }
  }
}

When I run this on my device the app crashes after executing the AVCapture.requestAccess line (the completion handler is not executed and no exceptions are thrown).

The only thing in the Console is:

2016-07-15 14:55:44.621819 testpp[2261:912051] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-07-15 14:55:44.626012 testpp[2261:912051] [MC] Reading from public effective user settings.
2016-07-15 14:55:59.284610 testpp[2261:912085] [access] <private>

Am I doing something wrong?

Wenda answered 15/7, 2016 at 19:0 Comment(3)
Works fine for me. What is "my device"? Could this be an iOS 10 beta bug?Detonation
Yes, I'm running iOS 10. :-( I'll try to track down an iOS 9 device - thanks.Wenda
That would be cool; let me know what you find out. My device is still iOS 9 so I simply set the deployment target to iOS 9 and ran my Xcode 8 project on it, without any problem.Detonation
L
19

Make sure you set a value for the Privacy - Camera Usage Description key in your Info.plist file when requesting camera access.

Layman answered 16/7, 2016 at 16:28 Comment(0)
O
1

enter image description here

Input the permissions you need to the info.plist

Oliveolivegreen answered 25/7, 2016 at 0:56 Comment(1)
like the image. linki.sstatic.net/I3RGQ.jpgOliveolivegreen

© 2022 - 2024 — McMap. All rights reserved.