XGAssetPickerController
是一款iOS相册选择器,支持图片、视频拍摄,多图片、多视频混选及预览, 支持Gif浏览(iOS11+
),多个相册目录同一图片/视频可自动排重,并具有记录已选图片/视频的功能。
该项目最低支持 iOS 8.0+
。
- 命令行进入
Demo
文件夹路径下,并执行pod install
- 打开
XGAssetPickerController-Demo.xcworkspace
- 在
Podfile
中添加pod 'XGAssetPickerController'
。 - 执行
pod install
或pod update
。 #import "XG_AssetPickerController.h"
- 下载 XGAssetPickerController 文件夹内的所有内容。
- 将 XGAssetPickerController 内的源文件添加(拖放)到你的工程。
- 由于用到了
FLAnimatedImage
,所以需要下载FLAnimatedImage
(https://github.com/Flipboard/FLAnimatedImage
),并添加(拖放)到你的工程。 #import "XG_AssetPickerController.h"
.
-
先使用
[[XG_AssetPickerManager manager] handleAuthorizationWithCompletion:^(XG_AuthorizationStatus aStatus) { }];
检查是否获取相册权限,然后根据XG_AuthorizationStatus
做进一步处理 -
初始化
XG_AssetPickerOptions
对象来配置选择器,maxAssetsCount
表示最大可选择数量,videoPickable
表示是否可选择视频,已选的图片或者视频会保存在pickedAssetModels
数组中。 -
使用初始化选择器
XG_AssetPickerController
,然后UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:photoPickerVc];
[self presentViewController:nav animated:YES completion:nil];
-
遵循
<XG_AssetPickerControllerDelegate>
协议,并实现协议方法:- (void)assetPickerController:(XG_AssetPickerController *)picker didFinishPickingAssets:(NSArray<XG_AssetModel *> *)assets;
,选择结果在参数assets
中。具体使用方法可参见示例Demo
-
如果运行崩溃,崩溃信息log为:
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription/NSCameraUsageDescription key with a string value explaining to the user how the app uses this data
. 请检查Info.plist
是否添加相册/相机权限:NSPhotoLibraryUsageDescription/NSCameraUsageDescription
-
模拟器环境下,虽然在工程的
Localizations
配置中添加了简体中文Chinese(Simplified)
,但相册名称仍会默认为英文,这是正常的,因为Localizations
在真机环境下才会生效(即真机环境下相册名称会显示成中文)。
XGAssetPickerController
使用 MIT 许可证,详情见 LICENSE 文件。
XGAssetPickerController
is an iOS album picker that supports mixed multi-image,multi-video selection and preview. Gif browsing is supproted on iOS 11.0+
. Same images or videos in different album can be automatically detected, and selected images or videos can be recorded.
This library requires iOS 8.0+
.
- Use the terminal to enter the path of
Demo
,then excutepod install
- Click
XGAssetPickerController-Demo.xcworkspace
- Add
pod 'XGAssetPickerController'
to your Podfile. - Run
pod install
orpod update
. #import "XG_AssetPickerController.h"
- Download all the files in the XGAssetPickerController subdirectory.
- Add the source files to your Xcode project.
- This library references
FLAnimatedImage
, so you need to downloadFLAnimatedImage
(https://github.com/Flipboard/FLAnimatedImage
) and add its source files to your Xcode project too. #import "XG_AssetPickerController.h"
.
- Check if you get an access to the photo library using
[[XG_AssetPickerManager manager] handleAuthorizationWithCompletion:^(XG_AuthorizationStatus aStatus) { }];
- Initialize a
XG_AssetPickerOptions
object to config theXG_AssetPickerController
- Initialize a
XG_AssetPickerController
usinginitWithOptions: delegate:
method,and present it usingUINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:photoPickerVc];
[self presentViewController:nav animated:YES completion:nil];
- Adopt the
XG_AssetPickerControllerDelegate
protocol and implement it's required methodassetPickerController: didFinishPickingAssets:
If your app crashed with message like This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription/NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
, please check if the corresponding usage description is added in the app's Info.plist.
XGAssetPickerController
is provided under the MIT license. See LICENSE
file for details.