{"id":16699679,"url":"https://github.com/dufflink/mediahandler","last_synced_at":"2025-03-14T05:22:11.429Z","repository":{"id":129658414,"uuid":"215240419","full_name":"dufflink/MediaHandler","owner":"dufflink","description":"A Swift library for work with photo library, camera and documents.","archived":false,"fork":false,"pushed_at":"2020-03-17T07:36:46.000Z","size":86,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T00:20:42.919Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dufflink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-15T07:57:23.000Z","updated_at":"2020-03-18T08:03:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0e94a65-debb-4ccc-a4af-1103decc1e34","html_url":"https://github.com/dufflink/MediaHandler","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dufflink%2FMediaHandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dufflink%2FMediaHandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dufflink%2FMediaHandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dufflink%2FMediaHandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dufflink","download_url":"https://codeload.github.com/dufflink/MediaHandler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243527399,"owners_count":20305210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T18:07:50.944Z","updated_at":"2025-03-14T05:22:11.396Z","avatar_url":"https://github.com/dufflink.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MediaHandler\n\nA swift library for work with photo library, camera and documents.\n\n## Using\n\n#### 1. Import Library\n\nYou can use Swift Package Manager for implement this library in your project by url of remote repository:\n[https://github.com/dufflink/MediaHandler](https://github.com/dufflink/MediaHandler)\n\n```swift\nimport MediaHandler\n```\n#### 2. Create MediaPicker object\n\n```swift\nlet mediaPicker = MediaPicker(rootViewController: self, maxFileSize: 100, maxImageSideSize: 1280)\n```\n`rootViewController` . This view controller need for presenting of pickers.\n\n`maxFileSize` (Optional). Use this parameter if you want to validate file size (MB) after picking. Validation will not be perform if this paramter is nil.\n\n`maxImageSideSize` (Optional). Use this parameter if you want to scale image by largest side with your custom value. Default value is 1280.\n\n#### 3. MediaPickerDelegate\n\n```swift\noverride func viewDidLoad() {\n    mediaPicker.filesDelegate = self\n}\n\nextension ViewController: MediaPickerDelegate {\n    \n    func didPick(_ attachment: UploadingAttachment, source: String) {\n        //This method will be call when attachment will be pick\n        \n        //source - type of picker menu (photolibrary, camera or documents)\n    }\n    \n    func pickedFileIsLarge() {\n        //This method will be call if file is large\n    }\n    \n    func userDidDeniedPhotoLibraryPermission() {\n        //This method will be call if user did denied photo library permission\n    }\n    \n    func userDidDeniedCameraPermission() {\n        //This method will be call if user did denied camera permission\n    }\n    \n}\n```\n\n#### 4. Public main methods\n\n\nUse public methods of mediaPicker in UIAlertActions of UIAlertController:\n\n`openDocumentPicker()`: Opens a iCloud view for selecting documents. This method return DocumentAttachment object in delegate (MediaPickerDelegate) method didPick(_ attachment: UploadingAttachment, source: String).\n\n`openPhotoLibrary(includeVideo: Bool)`: Opens a photo library menu with request of permission. This method return ImageAttachment (picture) or DocumentAttachment (video) object in delegate (MediaPickerDelegate) method didPick(_ attachment: UploadingAttachment, source: String)\n\n`openСamera(canRecordVideo: Bool, isFrontCamera: Bool = false)`: Opens a camera. This method return ImageAttachment (picture) or DocumentAttachment (video) object in delegate (MediaPickerDelegate) method didPick(_ attachment: UploadingAttachment, source: String)\n\n\n```swift\nmediaPicker.openPhotoLibrary(includeVideo: true)\nmediaPicker.openСamera(canRecordVideo: true)\nmediaPicker.openDocumentPicker()\n```\nUse Example:\n\nHere we create UIAlertController:\n\n```swift\nlet alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)\n\nlet openPhotoLibraryAction = UIAlertAction(title: \"Фотоальбомы\", style: .default) { _ in\n    self.model.mediaPicker.openPhotoLibrary(includeVideo: true)\n}\n\nalertController.addAction(openPhotoLibraryAction)\n```\nOr you can use custom view for call public methods\n\n## Attachment Icons\n\nFor use your own MIMEType icons, you need to override properties of Icons class:\n\n```swift\npublic class Icons {\n    \n    //.mov, .mp4, .wmv, .ogg, .webm\n    public static var movie: UIImage?\n    \n    //.jpeg, .png, .bmp, .gif\n    public static var picture: UIImage?\n    \n    //.rar, .zip\n    public static var archive: UIImage?\n    \n    //unknown\n    public static var file: UIImage?\n    \n    public static var pdf: UIImage?\n    public static var keynote: UIImage?\n    \n    public static var doc: UIImage?\n    public static var ppt: UIImage?\n    public static var xls: UIImage?\n    \n    public static var pages: UIImage?\n    public static var numbers: UIImage?\n    \n}\n```\nExample:\n\n```swift\nIcons.archive = UIImage(named: \"Archive\")\n```\nor\n\n```swift\nIcons.movie = R.image.movie()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdufflink%2Fmediahandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdufflink%2Fmediahandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdufflink%2Fmediahandler/lists"}