今天介绍一个非常简单的人脸识别SDK,一登官网,非常方便快捷!虽然功能不太完善,有兴趣的同僚可以研究一下,下面切入主题
导入类库###
pod "SuperID"
AppDelegate中引入头文件#import "SuperID.h"###
[[SuperID sharedInstance]registerAppWithAppID:@"51fd8946d072a54727ead360" withAppSecret:@"985d924b84435a0daff478fa"];
//开启SuperID SDK的调试模式,开发者在Release时,将该模式设置为NO.
[SuperID setDebugMode:YES];
//设置一登 SDK 的语言模式,默认为自动模式。
[SuperID setLanguageMode:SIDAutoMode];
在ViewController中遵循协议SuperIDDelegate设置代理###
-(void)viewWillAppear:(BOOL)animated{
[SuperID sharedInstance].delegate = self;
}
实现代理方法
/**
* 添加一登 SDK 的委托方法
*/
- (void)superID:(SuperID *)sender userDidFinishLoginWithUserInfo:(NSDictionary *)userInfo withOpenId:(NSString *)openId error:(NSError *)error{
if (!error) {
//授权登录成功
NSLog(@"userInfo:%@", userInfo);
NSLog(@"openId = %@", openId);
/**
userInfo:{
avatar = "xxxxx.jpg";
name = "\U5f90\U9a8f\U6770V1\Uff01";
persona = {
character = reserved;
gender = male;
generation = 90s;
location = {
city = "\U6df1\U5733";
country = CN;
province = "\U5e7f\U4e1c";
};
tags = (
eyeglasses
);
};
phone = 136xxxx9914;
}
openId = xxxxxxxxxxxxxx
*/
// 识别成功的处理事件
TableViewController *tableVC = [[TableViewController alloc]init];
tableVC.userInfo = userInfo;
tableVC.openId = openId;
tableVC.navigationItem.hidesBackButton = YES;
[self.navigationController pushViewController:tableVC animated:YES];
}else{
//授权登录失败
NSLog(@"Login Fail Error =%ld,%@",(long)[error code],[error localizedDescription]);
}
}
人脸识别按钮事件###
- (IBAction)faceLoginBtn:(UIButton *)sender {
NSError *error = nil;
id SIDLoginViewController = [[SuperID sharedInstance]obtainLoginViewControllerWithError:&error];
if (SIDLoginViewController) {
[self presentViewController:SIDLoginViewController animated:YES completion:nil];
}else{
NSLog(@"Error =%ld,%@",(long)[error code],[error localizedDescription]);
}
}
就这么几句代码非常便捷:Demo下载地址