Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

ios - Detect add photos only permission

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...