Permission to take photo OR get image from library

2020-06-04 07:51发布

问题:

The code below shows an example for my access to the image lib. No matter where I call the code (view) I do not see the permission dialog from the phone popping up and therefore cannot allow my app to access either camera or library.

Also, the privacy settings do not show my app either. Any thoughts? I'm going nuts.

       let imgPicker = UIImagePickerController()
        imgPicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        imgPicker.modalPresentationStyle = UIModalPresentationStyle.Popover
        self.presentViewController(imgPicker, animated: true, completion: nil)

another way I tried

            if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
                let imagePicker:UIImagePickerController = self.imagePickerController

                imagePicker.allowsEditing       =   true
                imagePicker.sourceType          =   UIImagePickerControllerSourceType.Camera
                imagePicker.cameraCaptureMode   =   UIImagePickerControllerCameraCaptureMode.Photo
                imagePicker.cameraDevice        =   UIImagePickerControllerCameraDevice.Rear
                imagePicker.showsCameraControls =   true
                imagePicker.navigationBarHidden =   true
                imagePicker.toolbarHidden       =   true
                imagePicker.delegate = self

            self.presentViewController(imagePicker, animated: true, completion: nil)
            }

回答1:

You need to set a new pair of Info.plist values, same as the String for Location Services would be in iOS8:

Just set your description string for those.



回答2:

Check info.plist.

if "Bundle display name" set as nothing,

At iOS 8.1 will popup permission window like this

"" Would Like to Access Your Photos

But at iOS 9, there is no popup permission at all.

Also, no permission setting, at Setting > Privacy > Photos > Your app name.

To solve this,

Remove "Bundle display name" in your info.plist.



回答3:

Apparently this appears to be an issue with iOS9. For some reason the permission access dialog does not pop up. I have successfully tested on iOS8, using the same code.