打包bundle文件
xcode
一、新建OS X->Framework & Library->Bundle新建iphone
二、在Build Settings->(null)-Deployment->iOS Deployment Target->選擇本身須要支持的最低系統。函數
三、build後會生成一個bundle包,但在包中的圖片由之前的png格式所有變成tiff格式。爲了防止這種格式轉變。須要在Build Settings->Architectures->Base SDK->選擇iOS的SDK要支持的版本。這時TARGETS中Build Setting->User-Defined中會出現一個新的Key:COMBINE_HIDPI_DEBUG_INFO,把它設置爲NO。ui
四、這樣建立的圖片資源不能使用[UIImage imageNamed:@「png」]來獲取了。須要使用路徑方式來讀取圖片。spa
這裏我使用了一個函數來獲取路徑。code
NSString *getKaYiKaImageBundlePath(NSString *filename);orm
NSString *getKaYiKaImageBundlePath(NSString *filename) {圖片
NSBundle *libBundle = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"KaYiKa.bundle"]];ip
if (libBundle && filename) {ci
NSString *path = [[libBundle resourcePath] stringByAppendingPathComponent:filename];
path = [path stringByAppendingString:@".png"];
return path;
}
return nil;
}
使用時直接用
[UIImage imageWithContentsOfFile:getKaYiKaImageBundlePath(@"tool_return_day")]獲取圖片。
直接導出方法:
1.添加 target --> other -->aggregate
2.在新建的Target裏邊添加一個腳本:Build Phases -->new Run Script Phase
3.填入下面腳本到 Run Script
# begin =============================================
# Sets the target folders and the final framework product.
# 若是工程名稱和Framework的Target名稱不同的話,要自定義FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME=${PROJECT_NAME}
# 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=${SRCROOT}/Products/${FMK_NAME}.bundle
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.bundle
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.bundle
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos -arch armv7 -arch armv7s -arch arm64 clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator -arch x86_64 clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${SRCROOT}/Products/"
# end ===============================================