Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NavigationController.pushviewController
- @IBAction func goToGalleryBtn(_ sender: Any) {
- if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
- PHPhotoLibrary.requestAuthorization { (status) in
- switch status {
- case .authorized:
- self.presentPhotoPickerController()
- break
- case .notDetermined:
- if status == PHAuthorizationStatus.authorized{
- self.presentPhotoPickerController()
- }
- case .restricted:
- let alert = UIAlertController(title: "Photo Library Restricted", message: "Photo Library access is restricted and cannot be accessed.", preferredStyle: .alert)
- let okAction = UIAlertAction(title: "OK", style: .default)
- alert.addAction(okAction)
- self.present(alert, animated: true)
- case .denied:
- let alert = UIAlertController(title: "Photo Library Denied", message: "Photo Library access was previously denied. Please update your Settings if you wish to change this.", preferredStyle: .alert)
- let goToSettingsAction = UIAlertAction(title: "Go to Settings", style: .default){(action) in
- DispatchQueue.main.async {
- let url = URL(string: UIApplication.openSettingsURLString)!
- UIApplication.shared.open(url, options: [:])
- }
- }
- let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
- alert.addAction(goToSettingsAction)
- alert.addAction(cancelAction)
- self.present(alert, animated: true)
- }
- }
- }
- }
- @IBAction func cancelBtn(_ sender: Any) {
- dismiss(animated: true, completion: nil)
- }
- }
- extension UserAvatarViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate{
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
- if let image = info[.editedImage] as? UIImage{
- imageGallery = image
- }else if let image = info[.originalImage] as? UIImage{
- imageGallery = image
- }
- dismiss(animated: true, completion: nil)
- let storyBoard: UIStoryboard = UIStoryboard(name: "HomeViewController", bundle: nil)
- let homeVC = storyBoard.instantiateViewController(withIdentifier: "HomeVC") as! HomeViewController
- homeVC.imageView = imageGallery
- // self.navigationController?.pushViewController(homeVC, animated: true)
- self.navigationController?.popViewController(animated: true)
- }
- func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
- dismiss(animated: true, completion: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement