/MediaPickersPresenterFramework

Handles fetching data from camera, documents, phone library

Primary LanguageSwiftMIT LicenseMIT

MediaPresenterFramework

This framework provides an easy way to handle camera, phone library and video pickers. It handles permissions and returns a picked data in a delegate.

Usage

0. Import module

1. Add Privacy Usage Description in your Info.plist for intended pickers you are going to use. - Important!

2. Subclass MediaPickerPresenter and conform to protocol:

    class ViewController: UIViewController, MediaPickerPresenter {
        
        var attachmentManager: AttachmentManager = AttachmentManager()

        //...

        func didSelectFromMediaPicker(_ file: FileInfo) {
            //do more with file...
        }

3. (Optional) Customize AttachmentManager:

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //For example:
        var titles = attachmentManager.settings.titles
        var settings = attachmentManager.settings
        
	//Customize titles
	titles.actionSheetTitle = "My title"
        titles.cancelTitle = "CANCEL"
        
	//Customize pickers settings
        settings.allowedAttachments = [.photoLibrary, .documents];
        settings.documentTypes = ["public.image", "public.data"];
        
	settings.libraryAllowsEditing = true
        settings.cameraAllowsEditing = true
    }

4. Open menu:

    presentAttachmentActionSheet()

5. Check the result in delegate:

    func didSelectFromMediaPicker(_ file: FileInfo) {
        print("Picked file: \(file.fileName)")
        //do more with file...
    }

Feel free to comment and share your thoughts.

References

There are sources that were very helpful for creating the framework:

License

The MIT License (MIT)

Piotr Błachewicz 2018