当我使用UIImagePicker访问我的照片库来选择照片时,应用程序有时会显示黑屏,有时会显示一个屏幕,表示我必须授予应用程序访问照片的权限。但是当我进入“设置”->“隐私”->“照片”时,没有应用程序出现在那里,也无法在“设置”中找到该应用程序。我读到必须向我的Info.plist添加两个值,但它们也没有起作用。是否有人遇到了同样的错误?我正在使用xcode 7、swift 2.0和iOS 9。
这是我提示用户访问相机权限的地方
@IBAction func cameraButtonPressed(sender: UIButton) {
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (UIAlertAction) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}
let cameraAction = UIAlertAction(title: "Take Photo", style: .Default) { (UIAlertAction) -> Void in
if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
self.imagePicker.allowsEditing = false
self.imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
self.imagePicker.cameraCaptureMode = .Photo
self.presentViewController(self.imagePicker, animated: true, completion: nil)
} else {
self.noCamera()
}
}
let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .Default) { (UIAlertAction) -> Void in
self.imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(self.imagePicker, animated: true, completion: nil)
}
actionSheet.addAction(photoLibraryAction)
actionSheet.addAction(cameraAction)
actionSheet.addAction(cancelAction)
self.presentViewController(actionSheet, animated: true, completion: nil)
}