美文网首页
可充FaceSDK iOS接入文档

可充FaceSDK iOS接入文档

作者: 我们只是GitHub的搬运工 | 来源:发表于2019-05-16 14:40 被阅读0次

    环境:
    iOS 9.0+ / Mac OS X 10.14+
    Xcode 10.0+
    Swift 4.0+

    SDK导入

    1.1 手动导入

    Swift4.x
    Swift5.x

    将KCFaceSDK/文件中的KCFace.framework,KCFaceBundle.bundle,KCFace.swift 导入你的项目中
    image.png

    使用

    import KCFace
    

    1.2 [推荐]pod方式导入

    use_frameworks! #注意如果pod中没有请添加use_frameworks!,如果被注释请取消注释
    pod 'KCFaceKit', '~> 1.0.0'#Swift4.x版本请使用1.0.0以下(不包含1.0版本)例:pod 'KCFaceKit'~>0.1.0'
    

    1.3 info.plist文件中添加相机隐私权限及描述

    Privacy - Camera Usage Description App需要您的同意,才能访问相机,以便于识别你的面部信息
    

    2 用法

    • 2.1 Swift调用

    • 2.1.1 [推荐]pod导入后可直接使用(库名)KCFace.方法名
    //配置SDK
    KCFace.configSDK("kechong", "cus", "", "", "kc", "kechong")
    ///如果app需要SDK提示用户开通免密支付需设置代理对线并实现代理方法
    KCFace.delegate = self
    ///启动SDK Ui
    KCFace.showKCFace(self) { (bool, desc) in
        if bool == true {
            print("sdk唤起成功!")
        }else{
            print("SDK唤起失败\(desc)")
        }
    }
    
    ///修改添加微信免密签名id
    //在调用前请先确定 已经调用过configSDK()配置SDK参数
    KCFace.updateContractId("contractId") { (bool) in
        if bool == true {
            print("修改成功!")
        }else{
            print("修改失败")
        }
    }
    
    /*获取平台消费记录*/
    //在调用前请先确定 已经调用过configSDK()配置SDK参数 
    KCFace.payRecords(0, 0) { (bool, resp) in
        if bool == true {
            //成功
            print("成功!\(resp)")
        }else{
            //
            print("失败\(resp)")
        }
    }
    

    KCSDKManager

    //配置SDK参数
    let manager = KCSDKManager.sharedInstances
    ///设置代理
    manager.delegate = self
    //配置SDK
    manager.configSDK("kechong", "cus", "", "", "kc", "kechong")
    //启动SDK
    manager.showKCFace(self) { (bool, desc) in
        if bool == true {
            print("sdk唤起成功!")
        }else{
            print("SDK唤起失败\(desc)")
        }
    }
    
    • 2.2 oc调用

    1,如过是纯OC的项目,需要在项目中新建一个swift文件(名字随意)然后根据提示添加桥接文件(注意:创建的.swift文件不能删除 oc/swift混编略过)

    桥接.png

    2,设置项目swift版本为 SDK对应的最低支持版本及以上(project->Build Settings ->Swift Compiler -Language -> Swift Language Version )

    //导入
    #import <KCFace/KCFace.h>
    
    //配置SDK 并启动SDK
    KCSDKManager *manager = [KCSDKManager sharedInstances];
    manager.delegate = self;
    [manager configSDK:@"kechong" :@"cus" :@"" :@"" :@"kc" :@"kechong"];
    [manager showKCFace:self complete:^(BOOL isSuss, NSString * _Nonnull desc) {
        if (isSuss) {
            NSLog(@"成功:%@",desc);
        }else{
            NSLog(@"失败:%@",desc);
        }
    }];
    

    3.Other

    pod search KCFaceKit 搜索库提示错误/或者搜索不到
    [!] Unable to find a pod with name, author, summary, or description matching `KCFaceKit`
    
    在终端进行以下操作
    
    pod setup
    
    pod repo update
    
    //更新repo完成后 还是搜索不到KCFaceKit在终端中执行 
    rm ~/Library/Caches/CocoaPods/search_index.json
    
    //再执行 search pod会重新创建本地pod库索引
    pod search KCFaceKit
    
    

    KCFace.framwrok包含真机和模拟器环境在发布时需要去除i386/x86_64

    • 添加自动去除模拟器平台脚本
      选中项目->TARGETS(项目)->Build Phases
      创建脚本.png

    复制以下脚本代码到script中即可

     APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
     
      # This script loops through the frameworks embedded in the application and
      # removes unused architectures.
      find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
      do
      FRAMEWORK_EXECUTABLE_NAME=$(defaults read    "$FRAMEWORK/Info.plist" CFBundleExecutable)
      FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTAB LE_NAME"
      echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
     
      EXTRACTED_ARCHS=()
     
      for ARCH in $ARCHS
      do
      echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
      lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o       "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
      EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
     done
     
      echo "Merging extracted architectures: ${ARCHS}"
      lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create   "${EXTRACTED_ARCHS[@]}"
      rm "${EXTRACTED_ARCHS[@]}"
     
      echo "Replacing original executable with thinned version"
      rm "$FRAMEWORK_EXECUTABLE_PATH"
      mv "$FRAMEWORK_EXECUTABLE_PATH-merged"    "$FRAMEWORK_EXECUTABLE_PATH"
     
      done
    
    添加脚本.png

    或者cd进framework目录手动移除

    lipo -info KCFace.framework/KCFace  # Architectures in the fat file: KCFace are: i386 x86_64 armv7 armv7s arm64
    # 移除x86_64, i386
    lipo -remove x86_64 KCFace.framework/KCFace -o KCFace.framework/KCFace
    lipo -remove i386 KCFace.framework/KCFace -o KCFace.framework/KCFace
    # 再次查看
    lipo -info KCFace.framework/KCFace # Architectures in the fat file: KCFace are: armv7 armv7s arm64
    

    相关文章

      网友评论

          本文标题:可充FaceSDK iOS接入文档

          本文链接:https://www.haomeiwen.com/subject/jyspaqtx.html