问题描述
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: { })
}
即使我使用上述代码将设置中的照片设置为从不,我仍然可以显示图像选择器并显示照片。在显示之前我会检查 PHPhotoLibrary.authorizationStatus()
,但我想知道这是预期的行为吗?
Even if I set access to Photos in Settings to "Never" with above code I can still present image picker and show photos. I'll check for PHPhotoLibrary.authorizationStatus()
before showing it, but I would like to know is this expected behaviour?
推荐答案
好的,你可以从答案和评论中把它拼凑起来,但试着讲一个更完整的故事......
Okay, you can sort of piece this together from answers and comments already, but to try to tell a more complete story...
在iOS 11中, UIImagePickerController
作为与您的应用程序分开的进程运行。这意味着:
In iOS 11, UIImagePickerController
runs as a separate process from your app. That means:
- 您的应用无法看到用户的整个照片库 - 它只为任何资产获得只读访问权限用户在图像选择器中选择。
- 由于(1),您的应用程序不需要照片库访问的标准隐私授权。用户明确选择在您的应用中使用的特定资产(或多个),这意味着用户授予您的应用程序读取相关资产的权限。
您可以在此处查看有关此。
You can see more about this in the WWDC17 talk on PhotoKit.
(顺便说一下,这个模型与你看到的相匹配或。您可以在Info.plist中放置 NSPhotoLibraryAddUsageDescription
- 然后系统的隐私设置会向用户表明他们未授予您查看或修改现有资产的许可,只是添加新的。
- As noted above,
UIImagePickerController
doesn't need blanket Privacy Settings permission because each use grants one-time read access for the specific assets chosen. If you need only to add new assets to the Photos library, use
UIImageWriteToSavedPhotosAlbum
orUISaveVideoAtPathToSavedPhotosAlbum
. With those you can putNSPhotoLibraryAddUsageDescription
in your Info.plist — then the system's Privacy Settings will make clear to the user that they're not giving your permission to see or modify existing assets, only to add new ones.
如果用户授予只添加权限,它只适用于那些UIKit函数 - 尝试使用 PHPhotoLibrary
仍然会提示(并要求Info.plist键)读/写访问权。
If the user grants add-only permission, it applies only to those UIKit functions — attempting to use PHPhotoLibrary
will still prompt for (and require the Info.plist key for) read/write access.
参见了解有关仅限添加的隐私设置的更多信息。
See this part of the WWDC17 talk for more on the add-only privacy setting.
这篇关于即使将设置设置为“从不”,也可以访问iOS11照片库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!