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
| buildSettings = { | ||
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| DEVELOPMENT_TEAM = Y2NHS7RD78; |
There was a problem hiding this comment.
replaced with original
| 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.
Removed onPermissionChange
|
|
||
| internal func checkAuthorizationStatus(){ | ||
|
|
||
| if #available(iOS 14, *) { |
There was a problem hiding this comment.
requestAuthorization is done on controller presentation, does nothing here. Should be replaced with the authorizationStatus
| func didTapManageButton(for status: PHAuthorizationStatus) { | ||
| switch status { | ||
| case .denied: | ||
| self.handleDeniedAccess() |
There was a problem hiding this comment.
controller is not shown if no access (full or limited), so .denied is never executed
There was a problem hiding this comment.
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.
extra constraint, already created in 113 by `titleLabel.trailingAnchor.constraint(lessThanOrEqualTo: self.manageButton.leadingAnchor, constant: -8),
There was a problem hiding this comment.
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") |
| 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.
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.
code style: extra empty lines across the PR after closing brackets.
| @objcMembers public class Settings : NSObject { | ||
| public static let shared = Settings() | ||
|
|
||
There was a problem hiding this comment.
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.
I get crash on iPad because the popoverPresentationController?.sourceView is not set. Send here the "manage" button so sheet is displayed properly