-
Notifications
You must be signed in to change notification settings - Fork 380
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
Permission handling in image picker #334
base: master
Are you sure you want to change the base?
Permission handling in image picker #334
Conversation
mithilesh-parmar
commented
Jun 1, 2021
- Check for PHAuthorization status in onViewDidLoad() of AssetViewController
- Show header for authorisation status with manage button
Example.xcodeproj/project.pbxproj
Outdated
@@ -432,14 +432,14 @@ | |||
buildSettings = { | |||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | |||
CODE_SIGN_STYLE = Automatic; | |||
DEVELOPMENT_TEAM = Y2NHS7RD78; |
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.
this should not be present in the PR
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.
replaced with original
@@ -47,6 +48,7 @@ import Photos | |||
var onDeselection: ((_ asset: PHAsset) -> Void)? | |||
var onCancel: ((_ assets: [PHAsset]) -> Void)? | |||
var onFinish: ((_ assets: [PHAsset]) -> Void)? | |||
var onPermissionChange: ((_ status: PHAuthorizationStatus) -> Void)? |
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.
not used anywhere
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.
Removed onPermissionChange
|
||
internal func checkAuthorizationStatus(){ | ||
|
||
if #available(iOS 14, *) { |
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.
requestAuthorization
is done on controller presentation, does nothing here. Should be replaced with the authorizationStatus
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.
Removed this method
func didTapManageButton(for status: PHAuthorizationStatus) { | ||
switch status { | ||
case .denied: | ||
self.handleDeniedAccess() |
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.
controller is not shown if no access (full or limited), so .denied
is never executed
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.
removed handling of .denied
access
|
||
manageButton.topAnchor.constraint(equalTo: self.topAnchor), | ||
manageButton.bottomAnchor.constraint(equalTo: self.bottomAnchor), | ||
manageButton.leadingAnchor.constraint(greaterThanOrEqualTo: self.titleLabel.trailingAnchor, constant: 8), |
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.
extra constraint, already created in 113 by `titleLabel.trailingAnchor.constraint(lessThanOrEqualTo: self.manageButton.leadingAnchor, constant: -8),
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.
Removed duplicate constraint
I have yet to check this out and try it. I've only skimmed through it so far. But this adds a feature where the image picker can show a header if it doesn't have been authorized to access a users photos? I did see a lot of user facing strings that weren't localised though which would need to be fixed. |
Yes, this mimics WhatsApp-like permission handling wherein if the app has limited access to photos it will show a header wherein the user can manage permission. I'll look into strings localisations |
And by that I don't mean that you should translate them into 20 different languages. |
Cool, thanks for the heads up! |
Added Localized strings @mikaoj |
|
||
let openSettinsgLocalizedText = NSLocalizedString("bsimagepicker.restrictedAccess.alert.openSettings.title", | ||
value: "Open Settings", | ||
comment: "Primart button title") |
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.
Primart - typo
manageButton.topAnchor.constraint(equalTo: self.topAnchor), | ||
manageButton.bottomAnchor.constraint(equalTo: self.bottomAnchor), | ||
manageButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16), | ||
manageButton.widthAnchor.constraint(greaterThanOrEqualToConstant: manageButton.runtimeSize().width) |
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.
is this runtimeSize needed + extension? Why not set hugging/compressing priority instead?
manageButton.bottomAnchor.constraint(equalTo: self.bottomAnchor), | ||
manageButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16), | ||
manageButton.widthAnchor.constraint(greaterThanOrEqualToConstant: manageButton.runtimeSize().width) | ||
|
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.
code style: extra empty lines across the PR after closing brackets.
@@ -26,7 +26,7 @@ import Photos | |||
@objc(BSImagePickerSettings) // Fix for ObjC header name conflicting. | |||
@objcMembers public class Settings : NSObject { | |||
public static let shared = Settings() | |||
|
|||
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.
code style: please try to change you indentation settings to match the default for the project so there no "empty" changes
let cancelAction = UIAlertAction(title: cancelLocalizedText, style: .cancel, handler: nil) | ||
actionSheet.addAction(cancelAction) | ||
|
||
present(actionSheet, animated: true, completion: nil) |
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.
I get crash on iPad because the popoverPresentationController?.sourceView is not set. Send here the "manage" button so sheet is displayed properly