【发布时间】:2015-12-22 10:47:49
【问题描述】:
当我使用 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)
}
【问题讨论】:
-
您的应用是否真的请求访问权限?
-
@ChrisSlowik 它实际上并没有显示请求权限的对话框
-
你在你的代码中告诉它吗?我问你做了什么。你没有给出任何迹象表明你实际上正在做应该做的事情来请求访问,所以很难说什么是错的。如果您没有告诉您的应用请求许可,那就是您的问题。否则你可能会遇到另一个问题。
-
你说:“这是我提示用户访问相机的地方”。我说哪里?我在那里没有看到提示访问相机的代码。
-
我问了一个类似的问题并提供了更多细节,但仍然无法弄清楚:stackoverflow.com/questions/32834212/…