Xcode 7 制作 framework
2016-03-18 本文已影响445人
牵线小丑
创建工程
同时将该OC头文件设置为 public(默认添加到Private,可拖动到Public):
添加框架源代码
添加脚本
添加生成模拟器与真机都可使用的 framework 的运行脚本。
- 给框架工程添加Target:File/New/Target
编译完脚本会自动弹出生成的framework的文件夹。
添加framework到工程
-
将目标 framework 和其所用到的资源文件拖到目标工程中
-
添加目标框架到复制文件中去
�打包提交到 App Store
在使用自制的 Framework 的应用程序打包提交到 App Store 的时候,可能会遇到以下问题“Unsupported architectures. Your executable contains unsupported architectures '[x86_64, i386]'”
,此时在你要打包提交的目标程序的Build Phases
下添加Run Script
,并将以下内容复制进去:
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
到此就结束了