1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#import "AliyunFacePlugin.h"
#import <AliyunFaceAuthFacade/AliyunFaceAuthFacade.h>
@implementation AliyunFacePlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"aliyun_face_plugin"
binaryMessenger:[registrar messenger]];
AliyunFacePlugin* instance = [[AliyunFacePlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
NSLog(@"enter getPlatformVersion");
result([@"" stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
return;
}
if ([@"init" isEqualToString:call.method]) {
NSLog(@"enter init");
[AliyunFaceAuthFacade init];
return;
}
if ([@"getMetaInfos" isEqualToString:call.method]) {
NSLog(@"enter getMetaInfos");
NSDictionary *metaInfo = [AliyunFaceAuthFacade getMetaInfo];
NSString *info = [self convertToJsonData: metaInfo];
result([@"" stringByAppendingString:info]);
return;
}
if ([@"verify" isEqualToString:call.method]) {
NSLog(@"enter verify");
id arguments = call.arguments;
NSString *certifyId = [arguments objectForKey:@"certifyId"];
if (certifyId == nil || [certifyId length] == 0) {
NSLog(@"certifyId is nil.");
return;
}
NSLog(@"certifyId: %@.", certifyId);
NSMutableDictionary *extParams = [NSMutableDictionary new];
UIViewController *vc = [self viewControllerWithWindow:nil];
[extParams setValue:vc forKey:@"currentCtr"]; // 必须要的参数
[AliyunFaceAuthFacade verifyWith:certifyId
extParams:extParams
onCompletion:^(ZIMResponse *response) {
result([NSString stringWithFormat:@"%lu,%@", response.code, response.reason]);
}];
return;
}
result(FlutterMethodNotImplemented);
}
#pragma mark - 辅助方法
- (NSString *)convertToJsonData:(NSDictionary *) dict {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:NSJSONWritingSortedKeys
error:&error];
NSString *jsonString;
if (!jsonData) {
NSLog(@"Error: %@", error);
} else {
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}
- (UIViewController *) viewControllerWithWindow:(UIWindow *)window {
UIWindow *windowToUse = window;
if(windowToUse == nil) {
for (UIWindow *windowF in [UIApplication sharedApplication].windows) {
if (windowF.isKeyWindow) {
windowToUse = windowF;
break;
}
}
}
UIViewController *topViewController = windowToUse.rootViewController;
while (topViewController.presentingViewController) {
topViewController = topViewController.presentingViewController;
}
return topViewController;
}
@end