https://github.com/janlionly/avatarimagepicker
A single line of code for selecting the optional editing image from Camera or Photo Library, including handling the authorizations of Photo library and Camera.
https://github.com/janlionly/avatarimagepicker
authorization avatar camera imagepicker imagepickercontroller photo-library
Last synced: 8 months ago
JSON representation
A single line of code for selecting the optional editing image from Camera or Photo Library, including handling the authorizations of Photo library and Camera.
- Host: GitHub
- URL: https://github.com/janlionly/avatarimagepicker
- Owner: janlionly
- License: mit
- Created: 2019-08-19T06:03:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-06T10:24:51.000Z (over 5 years ago)
- Last Synced: 2025-08-11T04:47:48.096Z (9 months ago)
- Topics: authorization, avatar, camera, imagepicker, imagepickercontroller, photo-library
- Language: Swift
- Homepage: https://github.com/janlionly/AvatarImagePicker
- Size: 17.1 MB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AvatarImagePicker & AuthSettings
& 
[](https://cocoapods.org/pods/AvatarImagePicker)
[](https://github.com/Carthage/Carthage)
[](https://github.com/janlionly/AvatarImagePicker/blob/master/LICENSE)
[](https://github.com/janlionly/AvatarImagePicker)

## Description
**AvatarImagePicker** is a photo library and camera Image Picker for iOS
written in Swift, it's just a single line of code, support for selecting user's avatar by Camera or Photo Library, editing the selected image. Also, it supports auth verification, if camera or photo library was denied, it will alert the user to the settings for opening it. it means to replace for UIImagePickerController. Compatible with both Swift and Objective-C.
## Installation
### CocoaPods
```ruby
pod 'AvatarImagePicker'
```
### Carthage
```ruby
github "janlionly/AvatarImagePicker"
```
### Swift Package Manager
- iOS: Open Xcode, File->Swift Packages, search input **https://github.com/janlionly/AvatarImagePicker.git**, and then select Version Up to Next Major **1.3.0** < .
- Or add dependencies in your `Package.swift`:
```swift
.package(url: "https://github.com/janlionly/AvatarImagePicker.git", .upToNextMajor(from: "1.3.0")),
```
## Usage
**AvatarImagePicker** is presented with an actionsheet for camera and photo library, and then presented an ImagePickerController, optional some properties supports to customize, like **sourceTypes**, **presentStyle** and **dismissAnimated**.
Remember to add **NSCameraUsageDescription** and **NSPhotoLibraryUsageDescription**'s keys for descriptions to your Info.plist
### Swift
```swift
let picker = AvatarImagePicker.instance
// optional: custom properties
picker.dismissAnimated = false // default is true
picker.sourceTypes = [.camera] // default is [.camera, .photoLibrary]
picker.presentStyle = .overFullScreen // default is .fullScreen
// this method includes authorizing for photolibrary and camera.
picker.present(allowsEditing: true, selected: { (image) in
// selected image
}) {
// tapped cancel
}
// v1.3.2 updated: support to customize actions for sheet
picker.sourceTypes = [.camera, .customAction]
weak var weakSelf = self
picker.customActions = ["Delete": { weakSelf?.imageView.image = nil }]
// or you can call only auth photolibrary and camera, it will alert the user to go to settings if the photolibrary or camera was denied.
let isAuthSuccess = AuthSettings.authPhotoLibrary(message: "auth photolibrary to get your avatar") {
print("auth success")
// go to present image picker controller(photo library), customize your operation here.
}
_ = AuthSettings.authCamera(message: "auth camera to get your avatar") {
print("auth success")
// go to present image picker controller(camera), customize your operation here.
}
```
### Objective-C
```objc
[[AvatarImagePicker avatarImagePicker] presentWithAllowsEditing:YES selected:^(UIImage * _Nonnull image) {
// selected image
} cancel:^{
// tapped cancel
}];
```
## Requirements
- iOS 9.0+
- Swift 4.2 to 5.2
## Author
Visit my github: [janlionly](https://github.com/janlionly)
Contact with me by email: janlionly@gmail.com
## Contribute
I would love you to contribute to **AvatarImagePicker**
## License
**AvatarImagePicker** is available under the MIT license. See the [LICENSE](https://github.com/janlionly/AvatarImagePicker/blob/master/LICENSE) file for more info.