Easily take a photo or video or choose from library
To run the example project, clone the repo and open iOS Example/iOS Example.xcodeproj.
To use it in your project, add an FDTakeController to your view controller and implement:
fdTakeController.didGetPhoto = {
(_ photo: UIImage, _ info: [AnyHashable : Any]) in
}
then call:
fdTakeController.present()
The full API is:
/// Public initializer
publicoverrideinit()
/// Convenience method for getting a photo
openclassfunc getPhotoWithCallback(getPhotoWithCallback callback:@escaping(_ photo:UIImage, _ info:[AnyHashable:Any])->Void)-><<error type>>
/// Convenience method for getting a video
openclassfunc getVideoWithCallback(getVideoWithCallback callback:@escaping(_ video:URL, _ info:[AnyHashable:Any])->Void)
/// Whether to allow selecting a photo
openvarallowsPhoto:Bool
/// Whether to allow selecting a video
openvarallowsVideo:Bool
/// Whether to allow capturing a photo/video with the camera
openvarallowsTake:Bool
/// Whether to allow selecting existing media
openvarallowsSelectFromLibrary:Bool
/// Whether to allow editing the media after capturing/selection
openvarallowsEditing:Bool
/// Whether to use full screen camera preview on the iPad
openvariPadUsesFullScreenCamera:Bool
/// Enable selfie mode by default
openvardefaultsToFrontCamera:Bool
/// The UIBarButtonItem to present from (may be replaced by overloaded methods)
openvarpresentingBarButtonItem:UIBarButtonItem?
/// The UIView to present from (may be replaced by overloaded methods)
openvarpresentingView:UIView?
/// The UIRect to present from (may be replaced by overloaded methods)
openvarpresentingRect:CGRect?
/// The UITabBar to present from (may be replaced by overloaded methods)
openvarpresentingTabBar:UITabBar?
/// The UIViewController to present from (may be replaced by overloaded methods)
open lazy varpresentingViewController:UIViewController{getset}
/// A photo was selected
openvardidGetPhoto:((_ photo:UIImage, _ info:[AnyHashable:Any])->Void)?
/// A video was selected
openvardidGetVideo:((_ video:URL, _ info:[AnyHashable:Any])->Void)?
/// The user did not attempt to select a photo
openvardidDeny:(()->Void)?
/// The user started selecting a photo or took a photo and then hit cancel
openvardidCancel:(()->Void)?
/// A photo or video was selected but the ImagePicker had NIL for EditedImage and OriginalImage
openvardidFail:(()->Void)?
/// Custom UI text (skips localization)
openvarcancelText:String?
/// Custom UI text (skips localization)
openvarchooseFromLibraryText:String?
/// Custom UI text (skips localization)
openvarchooseFromPhotoRollText:String?
/// Custom UI text (skips localization)
openvarnoSourcesText:String?
/// Custom UI text (skips localization)
openvartakePhotoText:String?
/// Custom UI text (skips localization)
openvartakeVideoText:String?
/// Presents the user with an option to take a photo or choose a photo from the library
openfunc present()
/// Dismisses the displayed view. Especially handy if the sheet is displayed while suspending the app,
open func dismiss()- See if device has camera
- Create action sheet with appropriate options ("Take Photo" or "Choose from Library"), as available
- Localize "Take Photo" and "Choose from Library" into user's language
- Wait for response
- Bring up image picker with selected image picking method
- Default to selfie mode if so configured
- Get response, extract image from a dictionary
- Dismiss picker, send image to delegate
- Supports iPhones, iPods, iPads and tvOS (but not tested)
- Supported languages:
- English
- Chinese Simplified
- Turkish (thanks Suleyman Melikoglu)
- French (thanks Guillaume Algis)
- Dutch (thanks Mathijs Kadijk)
- Chinese Traditional (thanks Qing Ao)
- German (thanks Lars Häuser)
- Russian (thanks Alexander Zubkov)
- Norwegian (thanks Sindre Sorhus)
- Arabic (thanks HadiIOS)
- Polish (thanks Jacek Kwiecień)
- Spanish (thanks David Jorge)
- Hebrew (thanks Asaf Siman-Tov)
- Danish (thanks kaspernissen)
- Sweedish (thanks Paul Peelen)
- Portugese (thanks Natan Rolnik)
- Greek (thanks Konstantinos)
- Italian (thanks Giuseppe Filograno)
- Hungarian (thanks Andras Kadar)
- Please help translate
FDTake.stringsto more languages
- Pure Swift support and iOS 8+ required
- Compile testing running on GitHub Actions
- In progress: functional test cases (please help)
- In progress: UI test cases (please help)
Add this to your project using Swift Package Manager. In Xcode that is simply: File > Swift Packages > Add Package Dependency... and you're done.
William Entriken, github.com@phor.net
This is a mature project and we do not expect to add new features unless something has already become state-of-the-art in other applications. Please be prepared to cite screenshots of other apps before making a feature request.
We support targets for the latest released versions of Xcode and Swift Package Manager. If there are incompatibilities, we will only support the latest released versions/combinations that are supported. If you would like to support pre-release versions of these packages, please open a pull request, not an issue.
FDTake is available under the MIT license. See the LICENSE file for more info.
This project's layout is based on https://github.com/fulldecent/swift6-module-template If you would like to change the layout, please change that project FIRST. Also you may appreciate that project has "recipes" -- you don't just change the code, you explain why you are doing things. As a maintainer this makes my job MUCH simpler. In a similar respect, if you are introducing non-minor changes, it will be VERY helpful if you could please reference to another project (like AlamoFire) that has seen and discussed the types of design challenges you are touching.) Thanks again and we all really do appreciate your contributions.