Swift 3 如何强制开启后置摄像头闪光灯?

How can the rear camera flash be forced to on in Swift 3?

我试图强制打开 imagePicker 的闪光灯,但是当我 运行 以下代码时,它默认关闭。在 Swift 3 中是否还需要执行其他操作以强制打开闪光灯?

  let imagePicker = UIImagePickerController()
  imagePicker.delegate = self
  imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
  imagePicker.allowsEditing = false
  imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.on
  imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.rear;
  self.present(imagePicker, animated: true, completion: nil)

之前有人在这里问过旧版本 Swift 的问题:

但是,为了让它在 Swift 3.

中工作,我似乎缺少一些细微之处

在完成闭包中设置相机闪光灯模式如下:

  self.present(imagePicker, animated: true)
  {
      imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.on
  }

完整出处如下:

  let imagePicker = UIImagePickerController()
  imagePicker.delegate = self
  imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
  imagePicker.allowsEditing = false
  imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.rear;

  self.present(imagePicker, animated: true)
  {
      imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.on
  }

已验证这适用于 Swift 3,但不确定它是否对旧版本有帮助。