Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. NavigationController.pushviewController
  2.  
  3. @IBAction func goToGalleryBtn(_ sender: Any) {
  4. if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
  5. PHPhotoLibrary.requestAuthorization { (status) in
  6. switch status {
  7. case .authorized:
  8. self.presentPhotoPickerController()
  9. break
  10. case .notDetermined:
  11. if status == PHAuthorizationStatus.authorized{
  12. self.presentPhotoPickerController()
  13. }
  14. case .restricted:
  15. let alert = UIAlertController(title: "Photo Library Restricted", message: "Photo Library access is restricted and cannot be accessed.", preferredStyle: .alert)
  16. let okAction = UIAlertAction(title: "OK", style: .default)
  17. alert.addAction(okAction)
  18. self.present(alert, animated: true)
  19. case .denied:
  20. 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)
  21. let goToSettingsAction = UIAlertAction(title: "Go to Settings", style: .default){(action) in
  22. DispatchQueue.main.async {
  23. let url = URL(string: UIApplication.openSettingsURLString)!
  24. UIApplication.shared.open(url, options: [:])
  25. }
  26. }
  27. let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
  28. alert.addAction(goToSettingsAction)
  29. alert.addAction(cancelAction)
  30. self.present(alert, animated: true)
  31. }
  32. }
  33. }
  34. }
  35.  
  36. @IBAction func cancelBtn(_ sender: Any) {
  37. dismiss(animated: true, completion: nil)
  38. }
  39. }
  40.  
  41. extension UserAvatarViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate{
  42. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
  43. if let image = info[.editedImage] as? UIImage{
  44. imageGallery = image
  45. }else if let image = info[.originalImage] as? UIImage{
  46. imageGallery = image
  47. }
  48. dismiss(animated: true, completion: nil)
  49.  
  50. let storyBoard: UIStoryboard = UIStoryboard(name: "HomeViewController", bundle: nil)
  51. let homeVC = storyBoard.instantiateViewController(withIdentifier: "HomeVC") as! HomeViewController
  52. homeVC.imageView = imageGallery
  53. // self.navigationController?.pushViewController(homeVC, animated: true)
  54. self.navigationController?.popViewController(animated: true)
  55. }
  56.  
  57. func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
  58. dismiss(animated: true, completion: nil)
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement