Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mithilesh-parmar
Copy link

  • Check for PHAuthorization status in onViewDidLoad() of AssetViewController
  • Show header for authorisation status with manage button

@@ -432,14 +432,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = Y2NHS7RD78;
Copy link

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

Copy link
Author

@mithilesh-parmar mithilesh-parmar Dec 19, 2021

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)?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used anywhere

Copy link
Author

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, *) {
Copy link

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

Copy link
Author

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()
Copy link

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

Copy link
Author

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),
Copy link

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed duplicate constraint

@mikaoj
Copy link
Owner

mikaoj commented Dec 19, 2021

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.

@mithilesh-parmar
Copy link
Author

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

@mikaoj
Copy link
Owner

mikaoj commented Dec 19, 2021

I'll look into strings localisations

And by that I don't mean that you should translate them into 20 different languages.
Just wrap them in NSLocalizedString with a good english default string and a key so anyone wanting it in another language in their app could translate it :)

@mithilesh-parmar
Copy link
Author

Cool, thanks for the heads up!

@mithilesh-parmar
Copy link
Author

Added Localized strings @mikaoj


let openSettinsgLocalizedText = NSLocalizedString("bsimagepicker.restrictedAccess.alert.openSettings.title",
value: "Open Settings",
comment: "Primart button title")
Copy link

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)
Copy link

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)

Copy link

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

Copy link

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)
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants