1、創(chuàng)建靜態(tài)庫(kù),我們這里只介紹使用framework類型,首先打開xcode -->菜單new-->project-->選擇右下角的靜態(tài)庫(kù):

2.1、進(jìn)入到項(xiàng)目目錄,創(chuàng)建podfile,(前提本地得先配置好cocoapods環(huán)境)
填寫需要導(dǎo)入的第三方:
target "YHAlertSDK" do
platform :ios,'8.0'
#useframeworks
#to avoid other people pod again, must point thirty version except UM
pod 'SVProgressHUD', '2.1.2'
end
2.2?、cd到podfile目錄,并執(zhí)行在命令窗口 pod install命令,結(jié)果如下圖:


3、打開xcworkspace,Ctr + B,即可生成framework庫(kù)

4.1、使用腳本進(jìn)行打包,先選擇file-->new-->target ,頂部選擇cross-platform,點(diǎn)擊Aggregate:

4.2 、此時(shí)項(xiàng)目界面如圖4一樣,我們選擇Build phase ,再點(diǎn)擊左上角的 + 號(hào),然后添加腳本,把腳本復(fù)制,粘貼上去。腳本可以直接全真機(jī)與模擬器的包,腳本代碼如下:
#!/bin/sh
#UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
UNIVERSAL_OUTPUTFOLDER=${SRCROOT}/Products
WORKSPACE_NAME=${PROJECT_NAME}.xcworkspace
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}"-configuration ${CONFIGURATION} -sdk iphoneos ONLY_ACTIVE_ARCH=NO? BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
#cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${UNIVERSAL_OUTPUTFOLDER}"
5、xcode左上角,選擇目標(biāo),genearteSDK, 運(yùn)行 或者Ctr + B便可腳本生成framework。如下圖:


總結(jié),文章介紹比較簡(jiǎn)單,需要對(duì)cocoapod有一定的了解。