
#import "RNReactNativeAliLiveDetect.h"
#import <RPSDK/RPSDK.h>
#import <React/UIView+React.h>
@implementation RNReactNativeAliLiveDetect

- (dispatch_queue_t)methodQueue
{
    return dispatch_get_main_queue();
}
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(initAliLiveDetectSDK){
    [RPSDK initialize:RPSDKEnvOnline]; //必须为RPSDKEnvOnline
}
RCT_EXPORT_METHOD(startVerfiy:verifyToken
                  successResolve:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject){
    UINavigationController *rootVC=[UIApplication sharedApplication].keyWindow.rootViewController;
    
    [RPSDK start:verifyToken rpCompleted:^(AUDIT auditState) {
        NSLog(@"verifyResult = %ld",(unsigned long)auditState);
        if(auditState == AUDIT_PASS) { //认证通过
            resolve(@"success");
        }
        else if(auditState == AUDIT_FAIL) { //认证不通过
            resolve(@"fail");
        }
        else if(auditState == AUDIT_IN_AUDIT) { //认证中，通常不会出现，只有在认证审核系统内部出现超时，未在限定时间内返回认证结果时出现。此时提示用户系统处理中，稍后查看认证结果即可。
            resolve(@"processing");
        }
        else if(auditState == AUDIT_NOT) { //未认证，用户取消
            resolve(@"cancel");
        }
        else if(auditState == AUDIT_EXCEPTION) { //系统异常
            resolve(@"error");
        }
    }withVC:rootVC];
    
}
@end


