Swift Framewore 中导入CommonCrypto 编写 MD5

最近想要把自己积累的东西总结一下,封装到一个 framework 中去,在想要在 swift 的 framework 中使用 CommonCrypto 中的方法进行 MD5加密时遇到问题,搜索了很多文章,最终找到一个个人觉得比较好的方案,这里分享给大家。

1.新建 target 选择 Aggregate,创建一个新的 target 名字为CommonCryptoModuleMap(可以自取,我用的是这个)

WechatIMG1.jpeg

2.按照图中的步骤给这个 Aggregate 添加一个运行脚本

WechatIMG2.jpeg

脚本代码如下

# 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,选择 build phases,在 target dependencies中添加刚才的那个 Aggregate。

WechatIMG3.jpeg

4.选在 build setting,在 header search paths 中添加${BUILT_PRODUCTS_DIR}/Aggregate 名,

WechatIMG4.jpeg

注意 不能忘记添加 $(inherited)

  1. Cmd+B 先 build 一下项目,然后就可以再你需要导入的地方使用import CommonCrypto
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容