昨天晚上爬帖,整理出的成果,有用就拿去,不谢. 下面正式开始~~~
分为两大步:
一, 自定义 Framework
二,使用Framework
一, 自定义 Framework
1,创建自定义framework 工程
2,创建自定义 framework 的类,相信大家都会了.但是还贴图.
3,将创建的类引入到以工程名命名的头文件中
4,配置 framework, 将要暴露的头文件配置好,很简单.
到此为止,直接编译得到的 framework 就是可用的,但是是有局限的,只能是在模拟器上的,真机直接就 GG了 ,恐怕为了 get 这个技能不只是为了ZB,所以为了真正的技术,还是要继续往下刨.comeon~~ follow me!
5,在原来的工程中,创建新的target, 名字按自己心情取.
然后添加 shell 执行脚本
shell 脚本如下:
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={FMK_NAME}.framework
Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR={FMK_NAME}.framework
SIMULATOR_DIR={FMK_NAME}.framework
-configuration ${CONFIGURATION}
Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "{INSTALL_DIR}/"
Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "{FMK_NAME}" "{FMK_NAME}" -output "{FMK_NAME}"
rm -r "${WRK_DIR}"
open "${INSTALL_DIR}"
6,选择刚刚创建的 target,command+B/R 编译,直接弹出生成的framework ,就是它,万能的 fw.
主要产物
二,使用Framework
1,创建一般的工程,名字无所谓,引入上面生成的 framework
重中之重来了,这个必须要添加的(特大号的字),直接上图
不然就是这样的结果:
Reason: image not found
以上完成后,就是调用了 ,so easy
结语:
是不是很简单,上手体验吧,get 新技能的必杀技,有了这个就可以让你的工程很简单,也可以发自己的framework 让别人用,高大上,有木有啊!!!哈哈
=============
2017年01月10日23:12:51 补充
检查 pod 版本,不能过低,如果低了自行更新 gem install cocoapods
注册 cocoapods : pod trunk register 110@qq.com ‘名字’ --verbose,去邮箱验证邮件
查看自己的信息 pod trunk me
蓝线为主要的命令
添加其他的维护人
pod trunk add-owner 名字 邮箱
先 clone 工程再创建podspec
pod spec create github.com/02002love/S… 可以自动生成很多,修改podspec 文件,
如下:
Pod::Spec.new do |s|
s.name = "SToolsKit"
s.version = "1.0.0"
s.summary = "自定义组件"
s.description = "i'm song"
s.homepage = "github.com/02002love/S…"
s.screenshots = "www.example.com/screenshots…", "www.example.com/screenshots…"
#s.license = "MIT (example)"
s.license = { :type => "MIT", :file => "FILE_LICENSE" }
s.author = { "xiaowei" => "songjinwei007@gmail.com" }
Or just: s.author = "xiaowei"
s.authors = { "xiaowei" => "songjinwei007@gmail.com" }
s.social_media_url = "twitter.com/xiaowei"
s.platform = :ios
s.platform = :ios, "5.0"
s.ios.deployment_target = "5.0"
s.osx.deployment_target = "10.7"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
s.source = { :git => "github.com/02002love/S…", :tag => "v#{s.version}" }
s.source_files = "Source/**/*.{h,m}"
s.exclude_files = "Classes/Exclude"
s.public_header_files = "Classes/**/*.h"
s.resource = "icon.png"
s.resources = "Resources/*.png"
s.preserve_paths = "FilesToSave", "MoreFilesToSave"
s.framework = "SomeFramework"
s.frameworks = "SomeFramework", "AnotherFramework"
s.library = "iconv"
s.libraries = "iconv", "xml2"
s.requires_arc = true
s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
s.dependency "JSONKit", "~> 1.4"
end
生成文件
执行:pod spec lint SToolsKit.podspec 校验文件,出现错误
问题1
问题2
待解决