Coder Social home page Coder Social logo

hamza-faroooq / swift-nativeimagevideopickermanager Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 260 KB

This class is used to make native image and video picker in a single use

License: MIT License

Swift 100.00%
swift xcode image video imagepicker imagepickercontroller videopicker protocol protocol-oriented protocol-oriented-programming

swift-nativeimagevideopickermanager's Introduction

Introduction

Hi, Humans!

My name is Hamza Farooq and I love 'Swift' programming. I always try to implement new ideas. Do check Swift-TopViewController and Swift-NativeActionSheetManager for this Picker to work properly and if you do not want to use these additional things, you can remove them from the NativeImageVideoPickerManager on your on.

Swift-NativeImageVideoPickerManager

This class is used to make native image and video picker in a single use

Images

Simple Usage

Do the following simple steps to add this Manager class in your project

First of all, follow the instructions written in Introduction section of this documentaion

Then, simply download or copy this code and place it in your project. (Click on the link, this will take you to the directory where NativeImageVideoPickerManager is placed)

Example

For Image

First set the delegate to self as mentioned below

ImagePickerManager.sharedInstance.imagePickerSelectedDelegate = self

Then simply call this function

ImagePickerManager.callGenericImagePickerActionSheet(presentingController: self, title: "Actions", message: "Add a photo to your gallary", buttonTitlesArray: ["Take Picture", "Choose From Library"])
        

This will automatically handle the permissions and all the stuff that you need to write again and again. After this write the Protocol to handle the response of the PickerManager

extension YourViewController: imagePickerSelectedProtocol, UIImagePickerControllerDelegate {
    
    func imagePickerSelectedFunction(selectedImage: UIImage?) {
        
        let mySelectedImage = selectedImage
        
        // do your stuff here
        
    }

}

For Video

Set the delegate for the video

ImagePickerManager.sharedInstance.videoPickerSelectedDelegate = self

Then call the function

ImagePickerManager.callGenericImagePickerActionSheet(presentingController: self, title: ALERT, message: "Choose from options given below", buttonTitlesArray: ["Take Video From Camera", "Choose Video From Library"], isVideo: true)

Then use the protocol to handle the response

extension YourViewController: videoPickerSelectedProtocol, UIImagePickerControllerDelegate {
        
    func videoPickerSelectedFunction(selectedVideo: NSURL?) {
        
        if let selectedVid = selectedVideo {
            
            // do your stuff here

        }
        
    }
    
}

There are several attributes that you can modify to change the behaviour of the video picker. In the manager class there is a limit of maximum length for the video, current limit is 30 seconds. The manager also uses the compression for the video, if you do not want to compress the video then you can modify the manager on your own.

Permissions

Last but not the least, don't forget to add the following permissions in info.plist file of your project.

<key>NSCameraUsageDescription</key>
<string>Grant access so that you can capture photo as profile image easily</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>Grant access so that you can upload your photo as profile image easily</string>

I uses this class for my own personal use, if you want to use some other methods or want to modify this class on your own, you can. :-)

Contributions

Your contributions are most welcomed. Do let me know if you find any kind of issue while using this file. Please open an issue to discuss that problem. Thanks

Auther

Hamza Farooq, [email protected]

License

MIT (Click Me O_o)

swift-nativeimagevideopickermanager's People

Contributors

hamza-faroooq avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.