LJTestPods
示例
要运行示例项目,请克隆仓库,并首先从 Example 目录执行 pod install
要求
安装
LJTestPods 可通过 CocoaPods 获得。要安装它,只需在 Podfile 中添加以下行
pod 'LJTestPods'
创建 Pod 公共库
1、打开终端,进入要构建私有库的工程目录,执行 pod lib create 你的工程名
,随后回答几个问题
What platform do you want to use?? [ iOS / macOS ]
> ios
What language do you want to use?? [ Swift / ObjC ]
> objc
Would you like to include a demo application with your library? [ Yes / No ]
> yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> none
Would you like to do view based testing? [ Yes / No ]
> yes
What is your class prefix?
> LJ
2、创建私有库的 Git 仓库地址,这里以 GitHub 为例,一个空的 3、配置 LJTestPods.podspec 文件 4、打开终端,进入 Example 文件夹,执行 pod install
,安装依赖项 5、添加库的源代码文件,在 class 文件添加类库,然后执行 pod install
6、在 demo 项目中测试类库功能 7、验证 LJTestPods.podspec 文件
pod lib lint LJTestPods.podspec --allow-warnings
完成后
Ignoring ffi-1.9.25 because its extensions are not built. Try: gem pristine ffi --version 1.9.25
-> LJTestPods (0.1.0)
- WARN | summary: The summary is not meaningful.
- NOTE | xcodebuild: note: Using new build system
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file. (in target 'App')
LJTestPods passed validation.
8、将源代码提交到 GitHub,并打上 tag
git remote add origin https://github.com/dabaosodmi0420/LJTestPods.git
git add .
git commit -a -m '提交0.1.0'
git pull origin master //第一次创建可以不用执行
git push origin master
//创建tag
git tag 0.1.0
git push origin 0.1.0
//校验.podspec 文件
pod lib lint LJTestPods.podspec --allow-warnings
//发布
pod trunk push LJTestPods.podspec --allow-warnings
//出错 [!] Unable to accept duplicate entry for: LJTestPods (0.1.0)
//适用于版本冲突,重新发布版本
git tag 0.1.1
git push --tags
git push origin master
pod trunk push LJTestPods.podspec --allow-warnings
//pod search
pod search LJTestPods
//报错 Unable to find a pod with name, author, summary, or description matching
pod setup
//删除 ~/Library/Caches/CocoaPods 目录下的 search_index.json 文件
rm ~/Library/Caches/CocoaPods/search_index.json
pod search LJTestPods
9、添加资源文件 注:OC工程的podfile通常不使用use_frameworks!,Swift和自行创建的lib库默认已有。关于这两点的区别,如果不使用framework,pod内的资源文件会被打包成bundle放在mainbundle下面。由于开发中每个pod库对于use_frameworks!的使用情况各不相同,我们在设计工具类时代码要兼容两者。
- (NSString *)imagePathWithName:(NSString *)imageName bundleName:(NSString *)bundleName{
if(bundleName == nil || imageName == nil){
@throw @"imageName 和 bundleName 不能为空";
}
if ([bundleName containsString:@".bundle"]) {
bundleName = [bundleName componentsSeparatedByString:@".bundle"].firstObject;
}
// Podfile 文件中没有使用 use_frameworks!
NSURL *bundelUrl = [[NSBundle mainBundle] URLForResource:bundleName withExtension:@"bundle"];
// Podfile 文件中使用了 use_framework!
if (!bundelUrl) {
bundelUrl = [[NSBundle mainBundle] URLForResource:@"Frameworks" withExtension:nil];
bundelUrl = [bundelUrl URLByAppendingPathComponent:@"LJTestPods"];//是pod的名字
bundelUrl = [bundelUrl URLByAppendingPathExtension:@"framework"];
NSBundle *bundle = [NSBundle bundleWithURL:bundelUrl];
bundelUrl = [bundle URLForResource:bundleName withExtension:@"bundle"];
}
NSAssert(bundelUrl, @"获取不到bundle");
if (bundelUrl) {
NSBundle *bundle = [NSBundle bundleWithURL:bundelUrl];
NSString *imagePath = [bundle pathForResource:imageName ofType:@"png"];
NSLog(@"%@",imagePath);
return imagePath;
}else{
return @"";
}
}