Created
February 12, 2018 02:14
-
-
Save sTinGe/fcfb7955ad4d437bcb2ba9fe76a80c1a to your computer and use it in GitHub Desktop.
default photo library for iOS camera roll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by SuStinge on 12/02/2018. | |
import UIKit | |
import Foundation | |
import AVFoundation | |
import MobileCoreServices | |
class PhotoLibraryHelper: NSObject { | |
public static let imagePicker = UIImagePickerController() | |
fileprivate let isPhotoLibraryAvailable = UIImagePickerController.isSourceTypeAvailable(.photoLibrary) | |
fileprivate let sourceTypePhotoAlbum = UIImagePickerControllerSourceType.photoLibrary | |
var delegate: UINavigationControllerDelegate & UIImagePickerControllerDelegate | |
var takePhotoIndex: Int? | |
init(delegate: UINavigationControllerDelegate & UIImagePickerControllerDelegate) { | |
self.delegate = delegate | |
} | |
func prepareImagePicker() { | |
if !isPhotoLibraryAvailable { | |
return | |
} | |
let type = kUTTypeImage as String | |
if let availableTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary) { | |
if availableTypes.contains(type) { | |
PhotoLibraryHelper.imagePicker.mediaTypes = [type] | |
PhotoLibraryHelper.imagePicker.sourceType = sourceTypePhotoAlbum | |
} | |
} | |
PhotoLibraryHelper.imagePicker.allowsEditing = true | |
PhotoLibraryHelper.imagePicker.delegate = delegate | |
print("photo library ready to present") | |
} | |
func getPhotoLibraryOn(_ onVC: UIViewController, _ index: Int? = nil) { | |
if !isPhotoLibraryAvailable { | |
return | |
} | |
takePhotoIndex = index | |
onVC.present(PhotoLibraryHelper.imagePicker, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment