Code Monkey home page Code Monkey logo

asimagepicker's Introduction

ASImagePicker

Manage the classic UIImagePickerController quickly and with extended functionality. Using ASImagePicker let you easily save an image locally and upload it remotely.

Easy to setup:

class ViewController: UIViewController {

    lazy var imagePicker = ASImagePicker(presenter: self)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }


    private func showAlertSheetForCameraOrLibrary() {
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        
        let actionCamera = UIAlertAction(title: "camera", style: .default) { (_) in
            self.imagePicker.delegate = self
            self.imagePicker.allowsEditing = true
            self.imagePicker.deviceCamera = .front
            self.imagePicker.open(.camera)
            
        }
        alert.addAction(actionCamera)
        
        let actionLibrary = UIAlertAction(title: "library", style: .default) { (_) in
            self.imagePicker.delegate = self
            self.imagePicker.allowsEditing = true
            self.imagePicker.open(.photoLibrary)
        }
        alert.addAction(actionLibrary)
        
        let actionCancel = UIAlertAction(title: "Cancel", style: .cancel)
        alert.addAction(actionCancel)
        self.present(alert, animated: true, completion: nil)
    }
}

Delegate implementation:

extension ViewController: ASImagePickerDelegate{
    
    //Get the picked image after the user select it.
    func selectedImage(_ pickedImage: UIImage, _ picker: ASImagePicker) {
        
        imagePicker.saveImage(localPath: "myLocalPath...") { (success) in
            
            if success {
                
            }else{
                
                //manage failure...
            }
        }
    }
    
    //Optional method to save image also remotely
    func configureURLRequestWith(_ imageData: Data) -> URLRequest? {
        
        var request = URLRequest(url: URL(string: "http://url.myurl.put.image/")!)
        request.httpMethod = "PUT"
        request.httpBody = imageData
        return request
    }
}

asimagepicker's People

Contributors

tokta 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.