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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容