CGLMediaPicker 0.3.0

CGLMediaPicker 0.3.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布时间最新发布2016年7月

Chris Ladd 维护。




  • 作者:
  • Chris Ladd

CGLMediaPicker 允许用户选择客户端提供的多媒体类型中的一个,并在用户成功选择或由于某种原因取消后运行完成块。受 ClusterPrePermissions 影响,目标是更轻量级,普遍允许客户端更加自由。

CGLMediaPicker 使用相同的一些非常棒的“模拟警报”策略大幅度减少用户选择不使用的情况。更重要的是,选择器负责处理所有权限和 UI,并在用户活跃选择时自动保留在内存中。

我的意思是,认真地讲: ALAuthorizationStatusUIImagePickerControllerDelegatePHImageRequestOptions?谁有时间为这些 $@*! 做事?

CGLMediaPicker 让用户提供照片变得和创建选择器对象、配置它一样简单

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

它负责呈现正确的相册选择器或相机组件。它负责请求权限,通知用户为什么缺少权限,何时缺少权限,并将他们发送到 Settings.app 以处理可能出现的任何问题。

简而言之,CGLMediaPicker 让您这个客户端说:“我想要用户给我一片媒体。”接着让您坐下来等待媒体的到来。

难道这听起来不舒服吗?

用法

__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];

安装

CGLMediaPicker 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "CGLMediaPicker"

作者:

Chris Ladd, [email protected]

许可证

CGLMediaPicker 根据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。