Image pic for my app from camera and gallery iOS swift

 Solution:

extension MyVC:UIImagePickerControllerDelegate,UINavigationControllerDelegate {

    

    func imgPic(btn:UIButton) {

        let alert:UIAlertController=UIAlertController(title: "Profile Image", message: nil, preferredStyle: UIAlertController.Style.actionSheet)

        

        let cameraAction = UIAlertAction(title: "Camera", style: UIAlertAction.Style.default) {

            UIAlertAction in

            self.openCamera()

        }

        let gallaryAction = UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default) {

            UIAlertAction in

            let authStatus = PHPhotoLibrary.authorizationStatus()

            switch (authStatus){

            case .notDetermined,.authorized:

                self.openGallery(btn:btn )

            case .restricted,.denied:

                self.showAlert(msg:"No access for photos", controller: self)

            case .limited:

                break

            @unknown default:

                break

            }

        }

        let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) {

            UIAlertAction in

        }

        alert.addAction(cameraAction)

        alert.addAction(gallaryAction)

        alert.addAction(cancelAction)

        if UIDevice.current.userInterfaceIdiom == .phone {

            self.present(alert, animated: true, completion: nil)

        }

        else {

           let popover = UIPopoverController(contentViewController: alert)

            popover!.present(from: btn.frame, in: self.view, permittedArrowDirections: UIPopoverArrowDirection.any, animated: true)

        }

    }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift