即使将设置设置为“从不”,也可以访问iOS11照片库。 [英] iOS11 photo library access is possible even if settings are set to "never"

查看:144
本文介绍了即使将设置设置为“从不”,也可以访问iOS11照片库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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. 您的应用无法看到用户的整个照片库 - 它只为任何资产获得只读访问权限用户在图像选择器中选择。

  2. 由于(1),您的应用程序不需要照片库访问的标准隐私授权。用户明确选择在您的应用中使用的特定资产(或多个),这意味着用户授予您的应用程序读取相关资产的权限。

您可以在此处查看有关此的更多信息WWDC17关于PhotoKit的讨论

You can see more about this in the WWDC17 talk on PhotoKit.

(顺便说一下,这个模型与你看到的相匹配;如果您显示联系人选择器,您的应用只会获得联系人的一次性联系信息(s) )用户选择,而不是对联系人数据库的持续读/写访问权限,因此联系人选择器不需要特殊的隐私权限。)

(By the way, this model matches what you've seen in the Contacts framework since iOS 9; if you show contact picker, your app only gets a one-time drop of contact information for the contact(s) the user picked, not ongoing read/write access to the Contacts database, so the contact picker doesn't require special privacy permission.)

PHPhotoLibrary 及其授权状态反映了用户可以从Se控制的Photos访问的全局读/写权限ttings>隐私。 (这是您的Info.plist需要 NSPhotoLibraryUsageDescription 。)任何使用 PHPhotoLibrary API都需要此权限,无论如何您的应用程序是否仅用于写入或仅用于阅读。自从在iOS 8中引入PhotoKit以来,情况就是如此。

PHPhotoLibrary and its authorization status reflect the global read/write permission for Photos access that users can control from Settings > Privacy. (That's the one where your Info.plist needs NSPhotoLibraryUsageDescription.) Any use of the PHPhotoLibrary API requires this permission, regardless of whether your app's use of that API is only for writing or only for reading. This has been true since PhotoKit was introduced in iOS 8.

如果你没有使用 PHPhotoLibrary PHAsset 等,iOS 11中有一些较新的权限选项(而不是Photos.framework API的一部分):

If you're not using PHPhotoLibrary, PHAsset, etc, there are narrower permission options that are new in iOS 11 (and not part of the Photos.framework API):

  • 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 or UISaveVideoAtPathToSavedPhotosAlbum. With those you can put NSPhotoLibraryAddUsageDescription 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.

参见 WWDC17演讲的这一部分了解有关仅限添加的隐私设置的更多信息。

See this part of the WWDC17 talk for more on the add-only privacy setting.

这篇关于即使将设置设置为“从不”,也可以访问iOS11照片库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆