通常项目都会有头像功能,为了给用户提供精美好看的头像,为了给开发者减少头像模块开发的工作量,而引用了AvatarCloudSDK。
大家可以通过pod直接导入
pod ‘AvatarCloudSDK’
传送门:github
本文讲解一下iOS版本:
1.功能及介绍
头文件:
#import <AvatarCloudSDK/AvatarCloudSDK.h>
SDK内部头像预览展示的属性:
//是否是圆
@property (nonatomic, assign) BOOL isCircle;
//圆角
@property (nonatomic, assign) CGFloat cornerRadius;
//链接超时时间
@property (nonatomic, assign) NSTimeInterval timeoutInterval;
//唤起容器
- (void)initWithParentController:(id)viewControlleranimated:(BOOL)animated;
/*
* 返回图片的 UIImage对象 或 NSData
*/
- (void)getimage:(void(^)(UIImage*image))imageBlock;
- (void)getimageData:(void(^)(NSData*imageData))imageBlock;
- (void)addAvatarCloudListener:(id<AvatarCloudListener>)listener;
移出监听:
- (void)removeAvatarCloudListener;
监听回调:
// 失败信息
- (void)avatarCloudError:(NSDictionary*)resultDic;
3.SDK使用
初始化
- appID 和 secretID可在云头像官网申请
[AvatarCloud@R_233_5025@ager initWithClient_id:@"appID" client_secret:@"secretID"];
然后就能在项目里直接唤起SDK的界面了
__weak typeof(self) weakSelf = self;
AvatarCloud@R_233_5025@ager *avatarCloud@R_233_5025@ager = [AvatarCloud@R_233_5025@ager sharedInstance];
[avatarCloud@R_233_5025@ager initWithParentController:self animated:YES];
[[AvatarCloud@R_233_5025@ager sharedInstance] getimage:^(UIImage*_Nonnull image) {
weakSelf.avatarView.image= image;
}];
4.SDK展示
结语:
AvatarSDK集成简单方便,可快速让用户选择精美好看的头像。
如果使用中有任何问题,可联系我,如果觉得还不错记得给一颗星哦。