检测仅添加照片权限 [英] Detect add photos only permission

查看:1982
本文介绍了检测仅添加照片权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ios 11中,我们现在有仅添加照片权限设置。

In ios 11 we now have "Add photos only" permission setting.

但我们现在如何确定设置了哪个照片库访问级别?
[PHPhotoLibrary authorizationStatus] 仅适用于读写权限检查。如果应用仅询问仅添加照片权限,则会保留 PHAuthorizationStatusNotDetermined 。如果用户将其从读取和写入更改为仅添加照片,则会提供 PHAuthorizationStatusDenied

But how we now determinate which photo library access level is set? [PHPhotoLibrary authorizationStatus] works only for "Read and Write" permission check. If app asked only for "Add photos only" permission then it stays PHAuthorizationStatusNotDetermined. If user changed it from "Read and Write" to "Add photos only" it gives PHAuthorizationStatusDenied.

那么,我怎么知道我的应用程序是否有权执行导出到相机胶卷功能,这不需要读取权限?

So, how can I tell if my app have permissions to do "Export to Camera Roll" feature, which dosen't require read permissions?

推荐答案

自iOS 11起,为了获得仅写入权限,您需要添加 info.plist 中的 NSPhotoLibraryAddUsageDescription
如果您想检查用户是否允许您这样做,则会出现此问题。它无法通过 [PHPhotoLibrary authorizationStatus] 方法完成,因为它会调出读/写弹出窗口(并且您需要 NSPhotoLibraryUsageDescription <您的 info.plist 中的/ code>也是如此。

since iOS 11, in order to gain only Write access you'll need to add the NSPhotoLibraryAddUsageDescription in your info.plist. The problem here arises if you want to check if the user allows you to do that. It cannot be done through the [PHPhotoLibrary authorizationStatus] method, since that calls out the read/write popup (and you'll need to have NSPhotoLibraryUsageDescription in your info.plist too).

如果你想检查用户是否给你的应用程序写入权限,你必须打电话给 UIImageWriteToSavedPhotosAlbum (我猜你已经打电话了,如果你想把数据添加到图库中),这会给你一个回调,告诉你保存是否有效,但更重要的是它向用户显示你的 NSPhotoLibraryAddUsageDescription 文字。

If you want to check if the user gave your app access to write, you'll have to call UIImageWriteToSavedPhotosAlbum (which I'm guessing you already call if you want to add data to the gallery), and that gives you a callback which tells you if the saving worked or not, but the bigger thing is that it shows the user your NSPhotoLibraryAddUsageDescription text.

现在,为了确保您对两者都有访问权限,您应该同时添加 NSPhotoLibraryAddUsageDescription NSPhotoLibraryUsageDescription 添加到您的 info.plist 并定期检查PHPhotoLibrary,如果失败,那么您只能检查何时保存数据使用 UIImageWriteToSavedPhotosAlbum 到库中。

Now, in order to make sure you have access on both, you should add both NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription added to your info.plist and do your regular check with the PHPhotoLibrary, and if that fails, then you can only check when you want to save the data to the library with UIImageWriteToSavedPhotosAlbum.

我说你只能用 UIImageWriteToSavedPhotosAlbum 查看,但你需要实际将图像保存到用户图库做到这一点,它是hacky,这是不,不。

I'd say you can check only with UIImageWriteToSavedPhotosAlbum but you need to actually save an image to the user gallery to do that and it's hacky, which is a no no.

这篇关于检测仅添加照片权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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