CGLMediaPicker 0.3.0

CGLMediaPicker 0.3.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jul 2016

Maintained by Chris Ladd.




  • By
  • Chris Ladd

CGLMediaPicker allows the user to choose a piece of multimedia of an array of types provided by the client, and runs a completion block once the user has either successfully chosen, or cancelled for some reason. Influenced by ClusterPrePermissions, with the goal of being lighter weight, and generally allowing clients to be more hands off.

CGLMediaPicker uses the same very nice "fake alert" strategy to dramatically cut down on users opting out. What's more, the picker takes care of all permissions and UI, and is automatically retained in memory for as long as the user is actively choosing.

I mean, seriously: ALAuthorizationStatus? UIImagePickerControllerDelegate? PHImageRequestOptions? Who's got time for that $@*!?

CGLMediaPicker makes letting users provide photos as simple as creating a picker object, configuring it, and:

picker.completion = ^(UIImage *image, NSDictionary *info, NSError *error){
    // doing something nice with your user's chosen image
};

It takes care of presenting the right photo picker or camera components. It takes care of asking for permissions, informing the user why permissions are lacking, when they're lacking, and sends them to Settings.app to take care of any problems they might need to.

In short, CGLMediaPicker lets you, the client, say: I would like the user to give me a piece of media. And then lets you sit back and wait for that media to arrive.

Doesn't that sound nice?

Usage

__weak __typeof(self) weakSelf = self;

// initialize a new picker
CGLMediaPicker *picker = [[CGLMediaPicker alloc] initWithViewController:self];

// give it a series of inputs -- this will automatically be narrowed down by the picker to the inputs actually available on the user's device. e.g. if they don't have a camera
picker.inputs = @[CGLMediaPickerOptionCamera, CGLMediaPickerOptionPhotoLibrary, CGLMediaPickerOptionUserLastPhoto];

// tell the user a little about what you'll use their photos for
picker.permissionMessage = NSLocalizedString(@"We'll use your photos to set the background to this view controller.", nil);

// add a completion. note that you don't have to maintain a reference to the picker -- it's stored internally by the class until the user has finished interacting with it.
picker.completion = ^(UIImage *image, NSDictionary *info, NSError *error){
    if (image) {
        weakSelf.imageView.image = image;
    }
};

// lastly, go ahead and pick. This will present your options to the user.
[picker pick];

Installation

CGLMediaPicker is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CGLMediaPicker"

Author

Chris Ladd, [email protected]

License

CGLMediaPicker is available under the MIT license. See the LICENSE file for more info.