如何在swift的framework中使用加密框架CommonCrypto/CommonCrypto.h

此文章是https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework翻译而来。

  1. 首先你需要创建一个Aggregate targetAggregate target create
  2. 如下图设置runScript
    添加runScript
    runScript代码如下:
    # This if-statement means we'll only run the main script if the CommonCryptoModuleMap directory doesn't exist
    # Because otherwise the rest of the script causes a full recompile for anything where CommonCrypto is a dependency
    # Do a "Clean Build Folder" to remove this directory and trigger the rest of the script to run
    if [ -d "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap" ]; then
        echo "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap directory already exists, so skipping the rest of the script."
        exit 0
    fi
    
    mkdir -p "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap"
    cat <<EOF > "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap/module.modulemap"
    module CommonCrypto [system] {
        header "${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    EOF
  3. framework添加target
    addtaget
  4. 添加支持的平台
    平台支持
  5. 设置引用路径
    路径

    此处切记要加上:
    $(inherited)
    ${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap

    之后就可以在对应的文件 import  CommonCrypto ,编译一下可以编译通过的。

  6. Xcode 10现在附带了一个CommonCrypto模块映射,因此不需要进行这种变通。如果您想同时支持Xcode 9和10,您可以在运行脚本阶段检查模块映射是否存在,例如:

    COMMON_CRYPTO_DIR="${SDKROOT}/usr/include/CommonCrypto"
    if [ -f "${COMMON_CRYPTO_DIR}/module.modulemap" ]
    then
       echo "CommonCrypto already exists, skipping"
    else
        # generate the module map, using the original code above
    fi
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值