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

Images not shown first time after getting permission iOS 14 #319

Open
SohaibSiddique opened this issue Dec 21, 2020 · 7 comments
Open

Images not shown first time after getting permission iOS 14 #319

SohaibSiddique opened this issue Dec 21, 2020 · 7 comments

Comments

@SohaibSiddique
Copy link

SohaibSiddique commented Dec 21, 2020

I'm using this library on iOS 14 and when I install my app the first time and allow permission to access all photos then there is no image in the picker.
after cancel when again press the upload button and I got all pictures.

this is my code to present the image picker.

let imagePicker = ImagePickerController() imagePicker.settings.fetch.assets.supportedMediaTypes = [.image] imagePicker.settings.selection.max = 5 imagePicker.settings.theme.selectionStyle = .numbered imagePicker.settings.selection.unselectOnReachingMax = false let options = imagePicker.settings.fetch.album.options imagePicker.settings.fetch.album.fetchResults = [ PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: options), PHAssetCollection.fetchAssetCollections(with: .album, subtype: .albumRegular, options: options), ]

@SohaibSiddique SohaibSiddique changed the title Images not shown first time after getting permison Images not shown first time after getting permison iOS 14 Dec 21, 2020
@SohaibSiddique SohaibSiddique changed the title Images not shown first time after getting permison iOS 14 Images not shown first time after getting permission iOS 14 Dec 21, 2020
@oztoygar
Copy link

oztoygar commented Feb 5, 2021

I am facing the same problem, did you find a solution?

@mikaoj
Copy link
Owner

mikaoj commented Feb 5, 2021

Does it work if you don't set a custom fetch result?

@swaminathan-venkataraman
Copy link

swaminathan-venkataraman commented Feb 11, 2021

Same problem faced here and I have not used any custom fetch results

Getting - _BSMachError: port 6c03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND" - in console

@BlTWISE
Copy link

BlTWISE commented Mar 5, 2021

Also getting this same problem

@SohaibSiddique
Copy link
Author

func photoAuthorization(authorized: @escaping () -> Void, unauthorized: @escaping () -> Void) { PHPhotoLibrary.requestAuthorization { (status) in switch status { case .authorized: DispatchQueue.main.async(execute: authorized) default: DispatchQueue.main.async(execute: unauthorized) } } }

and user thsi as

UIHelper.sharedInstance.photoAuthorization { self.setupImagePicker() } unauthorized: { SVProgressHUD.dismiss() self.showAlertViewSettings() }

@BlTWISE
Copy link

BlTWISE commented Mar 7, 2021

I solved this issue on my application by wrapping the function that presents the ImagePickerController in a wrapper function that asks the user for authorization prior to presenting the picker:

PHPhotoLibrary.requestAuthorization { (auth_status) in 

    if auth_status == .denied || auth_status == .notDetermined {
        /* User denied permission or left the authorization in an undetermined state
        Enter code here to handle this event or leave it blank if you don't want to do anything
        */
    } else {
        /*
        auth_status is either authorized, limited, or restricted. Call wrapper function
        */
        self.FunctionThatPresentsImagePickerController()
    }

}

However in iOS 14 when the PHAuthorizationStatus is limited the prompt will never re-appear, leaving users to only select the initial images they selected and nothing else. Upon further investigation I found that this is intended behavior on Apple's end- they only prompt to ask you to select more images once per app session. Odd design but that's how it works right now.

This solution is an anti-pattern and only really serves as a temporary solution until a fix is made.

@swaminathan-venkataraman
Copy link

swaminathan-venkataraman commented Mar 8, 2021

The issue was because of the authorisation status

I solved this issue on my application by wrapping the function that presents the ImagePickerController in a wrapper function that asks the user for authorization prior to presenting the picker:

PHPhotoLibrary.requestAuthorization { (auth_status) in 

    if auth_status == .denied || auth_status == .notDetermined {
        /* User denied permission or left the authorization in an undetermined state
        Enter code here to handle this event or leave it blank if you don't want to do anything
        */
    } else {
        /*
        auth_status is either authorized, limited, or restricted. Call wrapper function
        */
        self.FunctionThatPresentsImagePickerController()
    }

}

However in iOS 14 when the PHAuthorizationStatus is limited the prompt will never re-appear, leaving users to only select the initial images they selected and nothing else. Upon further investigation I found that this is intended behavior on Apple's end- they only prompt to ask you to select more images once per app session. Odd design but that's how it works right now.

This solution is an anti-pattern and only really serves as a temporary solution until a fix is made.

The was the solution for my case as well. However instead of checking the status I manually asked for premission using the PHPhotoLibrary.requestAuthorization and in the callback I presented the ImagePicker using the UIViewController's present method instead of presentImagePicker() provided by the library.

EG:

PHPhotoLibrary.requestAuthorization {
    (status) in
    switch status {
        case .authorized:
        self.present(imagePicker, animated: true)
        case .denied:
        // Handle the denied logic
        default:
        break
    }

}

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

No branches or pull requests

5 participants