一、如何 制作一个 可以在模拟器 和真机同时 使用的 iOS Framework
1、选择 Cocoa Touch Framework
2、添加静态库的代码,让编译的 .m文件出现在Compile Sources , 需要暴露的头文件 出現在 Public,如果沒有,把它拖移或新增到下图这样:
3、之后再真机和模拟器的中Scheme 下,分别 Build 静态库:
4、在 Build 的時候,SDK 就默默產生了:
在 Products 的 .framework 选中后show in finder就可以看到 Debug-iphoneos 以及 Debug-iphonesimulator。
二:要想真机和模拟器同时 可用这个 framework,必须合并他们。可以用终端命令手动合并。
不过xcode 提供了 Aggregate 自动合并方式。现仅说下 Aggregate 合并方式:
1. 在 xcode 中新建 Aggregate Target:
2. 添加 Run Script:
3. Script 中输入如下内容:
# Sets the target folders and the final framework product. FRAMEWORK_NAME="AVOSCloud-iOS" FRAMEWORK_VERSION=1.0 FRAMEWORK_CONFIG=Release # Install dir will be the final output to the framework. # The following line create it in the root folder of the current project. INSTALL_DIR=${PROJECT_DIR}/Products/${FRAMEWORK_NAME}.framework # Working dir will be deleted after the framework creation. WORK_DIR=build DEVICE_DIR=${WORK_DIR}/${FRAMEWORK_CONFIG}-iphoneos/${FRAMEWORK_NAME}.framework SIMULATOR_DIR=${WORK_DIR}/${FRAMEWORK_CONFIG}-iphonesimulator/${FRAMEWORK_NAME}.framework xcodebuild -configuration "${FRAMEWORK_CONFIG}" -target "${FRAMEWORK_NAME}" -sdk iphoneos echo "Build simulator" xcodebuild -configuration "${FRAMEWORK_CONFIG}" -target "${FRAMEWORK_NAME}" -sdk iphonesimulator # Creates install directory if it not exits. if [ ! -d "${INSTALL_DIR}" ] then mkdir -p "${INSTALL_DIR}" fi # Creates headers directory if it not exits. if [ ! -d "${INSTALL_DIR}/Headers" ] then mkdir -p "${INSTALL_DIR}/Headers" fi # Remove all files in the headers diectory. for file in `ls "${INSTALL_DIR}/Headers"` do rm "${INSTALL_DIR}/Headers/${file}" done # Remove binary library file. rm -f ${INSTALL_DIR}/${FRAMEWORK_NAME} # Copies the headers files to the final product folder. if [ -d "${DEVICE_DIR}/Headers" ] then for file in `ls "${DEVICE_DIR}/Headers"` do cp "${DEVICE_DIR}/Headers/${file}" "${INSTALL_DIR}/Headers/${file}" done fi # copy nibs to bundle,then copy bundle to final folder BUNDLE_DIR=${DEVICE_DIR}/${FRAMEWORK_NAME}.bundle if [ -d "${BUNDLE_DIR}" ];then if ls ${DEVICE_DIR}/*.nib >/dev/null 2>&1;then rm -rf ${BUNDLE_DIR}/*.nib cp -rf ${DEVICE_DIR}/*.nib ${BUNDLE_DIR} fi rm -rf "${INSTALL_DIR}/${FRAMEWORK_NAME}.bundle" cp -R "${BUNDLE_DIR}" "${INSTALL_DIR}/${FRAMEWORK_NAME}.bundle" fi echo "Merge with simulator" # Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product. lipo -create "${DEVICE_DIR}/${FRAMEWORK_NAME}" "${SIMULATOR_DIR}/${FRAMEWORK_NAME}" -output "${INSTALL_DIR}/${FRAMEWORK_NAME}" rm -r "${WORK_DIR}" open "${INSTALL_DIR}"