-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept limited photo library authorization #22
base: main
Are you sure you want to change the base?
Changes from 3 commits
d46f969
7878b28
5cd6f12
3d4b017
74b7bf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,20 @@ import Photos | |
import os.log | ||
|
||
class PhotoLibrary { | ||
|
||
static func checkAuthorization() async -> Bool { | ||
switch PHPhotoLibrary.authorizationStatus(for: .readWrite) { | ||
static func checkAuthorization(status: PHAuthorizationStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)) async -> Bool { | ||
switch status { | ||
case .authorized: | ||
logger.debug("Photo library access authorized.") | ||
return true | ||
case .notDetermined: | ||
logger.debug("Photo library access not determined.") | ||
return await PHPhotoLibrary.requestAuthorization(for: .readWrite) == .authorized | ||
return await checkAuthorization(status: PHPhotoLibrary.requestAuthorization(for: .readWrite)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I think this fixes the issue! I was only considering limited authorization when checking if already authorized. I also needed to accept limited authorization at the time of request. Let me know if you want me to restructure this code somehow. I think the recursive nature is a bit weird, but I assume the OS won't return It's worth noting there's a minor logging behavior change here. Previously, you wouldn't log the new status after requesting authorization. Now, we do. If you want me to refactor this, let me know how! If logging new status after request isn't your preference, I can just do something simple like |
||
case .denied: | ||
logger.debug("Photo library access denied.") | ||
return false | ||
case .limited: | ||
logger.debug("Photo library access limited.") | ||
return false | ||
return true | ||
case .restricted: | ||
logger.debug("Photo library access restricted.") | ||
return false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops almost forgot to swap this out
I think I don't like using the default argument in this way, but waiting for feedback re: logs & style before changing anything