快照中的相机和照片库的隐私问题

我的应用程序最初在各种设备上访问相机和照片库时没有任何问题。

现在我发现在某些设备上我无法访问相机或照片库,在我尝试访问相机和照片后,应用程序在隐私设置中根本不显示。

无论我做什么,我都无法让IOS识别我的应用程序。

我该怎么做才能访问相机和照片库,并让我的应用程序出现在隐私设置中? 码:

@IBAction func openCameraButton(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) == true { let imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = .Camera//UIImagePickerControllerSourceType.Camera; imagePicker.allowsEditing = false self.presentViewController(imagePicker, animated: true, completion: nil) }else{ noCamera() } } @IBAction func openPhotoLibraryButton(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) == true { let imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.allowsEditing = true self.presentViewController(imagePicker, animated: true, completion: nil) }else{ noAccess() } } 

我使用此代码进行可访问性检查并在需要时请求它:

 import AVFoundation import Photos func getCameraAccessibilityAndRequestIfNeeded(completion: (isAccesible: Bool)->Void) { let authorizationState = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) switch authorizationState { case .NotDetermined: AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (didAllow) in completion(isAccesible: didAllow) }) case .Restricted: completion(isAccesible: false) case .Denied: completion(isAccesible: true) case .Authorized: completion(isAccesible: true) } } func getPhotoRollAccessibilityAndRequestIfNeeded(completion: (isAccesible: Bool)->Void) { PHPhotoLibrary.requestAuthorization { (status) in switch status { case .Authorized: completion(isAccesible: true) case .Restricted, .Denied , .NotDetermined: completion(isAccesible: false) } } } 

用法:

 self.getCameraAccessibilityAndRequestIfNeeded { (isAccesible) in if isAccesible { // Access confirmed } else { // No access } } self.getPhotoRollAccessibilityAndRequestIfNeeded { (isAccesible) in if isAccesible { // Access confirm } else { // No access } } 

最后答案非常简单:

我正在做按钮动作中的imagePicker = UIImagePickerController()将其移动到类名以下,并且相机权限又回来了。

我现在已经在所有IOS设备上测试了我的代码 – 在iPhone 4s和iPod 5触摸的实际设备上以及模拟器上的其余设备 – 唯一不允许访问照片库并且不在隐私中显示应用程序的设备是iPhone 6的iPad Air 2和视网膜 – 所以看起来它也可能与显示器有关。

有没有其他人有这个问题?