打包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 ===============================================