CocoaPods创建私有库,重构项目必备技能

开始阅读本文前默认已安装CocoaPods环境

背景
为啥要学会创建私有库.png

  • 在实际开发中可能会遇到在pod集成第三方库的时候,修改了源码,每一次pod 更新的时候都要小心翼翼的

  • 封装的组件和模块需要在公司多个业务App里使用的时候,用pod管理会更容易维护和管理

  • 一个较大的APP需要拆分出来两个或以上相互独立的APP时候,也可以用pod进行管理。

  • 等等。。。。。
    这些都是我在实际中遇到的迫切需要创建私有库的问题。

看之前可以了解一下CocoaPods原理,介绍文章挺多的 ,我就不啰嗦了
CocoaPods原理点这里

开始跟着我创建私有库吧

1.创建podspec文件

  1. 什么是podspec?文件夹打开~/.cocoapods/repos看到

cocoapods官方specs集合.png

specs存放的就是cocoapod官网库的specification:说明书,通过这个podspec文件里的信息,找到对应资源URL,然后clone到我们的pod中。可以理解为书的目录,我们查找第三方库的时候实际就是查找这个specs集合。所以我们创建私有库第一步就是创建我们的spec,目录。

  1. 开始创建私有库podspec,理解为pod私有库说明书

下面我会以我在实际开发中将修改过的网易云信的SDK放在私有库中过程进行一步步操作

在github上创建一个存放specification的仓库,注意不是存放源码的库,一定不要搞错了

创建spec私有库.png

我建议先创建空的repository,为了区分命名最好以spec为后缀,说明这是存说明书的库

然后将这个库添加到~/.cocoapods/repos中,操作很简单,终端执行pod命令pod repo add TDNIMKitSpec git@github.com:strivever/TDNIMKitSpec.git

终端pod命令.png

命令格式:pod repo add 【specName】 【spec远程仓库地址】第一步完成,GOGOGO

2.制作我们的pod库

  1. cocoapods为我们提供了模板,cd 到你需要创建的文件夹里,然后pod lib create TDNIMKit( pod lib create 【你的pod库名】)命令,等待clone模板

    pod lib create.png

    等待一会.......
    templete.png

    填写几个配置,很简单,根据实际需要选择即可。我选择的是iOS平台,object-C语言,创建demo,不需要测试框架等等。
    配置完成之后,会自动打开拉取的模板工程。

  2. 以上都很简单,还是比较顺畅的,下边继续GO
    replaceMe.png

Finder进入ReplaceMe.m文件夹
showInFinder.png

在Finder中将你自己编写的源码替换放在ReplaceMe.m文件夹下。
自己源代码放入文件夹.png

文件放的位置不一定必须在模板中的Classes中,只要后边路径填写正确即可。如图,我是直接放在了TDNIMKit下,Classes存放的是代码,NIMSDK存放的是SDK和.a文件,Resources是图片等资源文件。

  1. 文件导入成功之后,再回到我们的工程文件,打开Podspec Metadata文件夹下的TDNIMKit.podspec文件,进行编辑,这是最重要也是最容易出错的一步。
    看一下默认的podspec文件ruby代码:我简单的注释了一下
Pod::Spec.new do |s|
  #pod私有库名称
  s.name             = 'TDNIMKit'
  #pod私有库版本号
  s.version          = '0.1.0'
  #pod私有库概要
  s.summary          = 'A short description of TDNIMKit.'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC
  #主要,最好能访问
  s.homepage         = 'https://github.com/458362366@qq.com/TDNIMKit'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  #开源协议
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  #开源作者
  s.author           = 'Striver'
  #源码地址,clone时候就需要使用这个地址跟版本拉取
  s.source           = { :git => 'https://github.com/458362366@qq.com/TDNIMKit.git', :tag =>'0.1.0' }
  #支持的系统版本
  s.ios.deployment_target = '8.0'
  #源码相对路径
  s.source_files = 'TDNIMKit/Classes/**/*'
  
  # s.resource_bundles = {
  #   'TDNIMKit' => ['TDNIMKit/Assets/*.png']
  # }
  # s.public_header_files = 'Pod/Classes/**/*.h'
  #需要使用的框架
  # s.frameworks = 'UIKit', 'MapKit'
  #依赖的其它第三方库
  # s.dependency 'AFNetworking', '~> 2.3'
end

然后我来编辑一下这个podspec:

s.source_files代码相对路径,这个最容易出错,我详细解释这个路径怎么去填:

WeChate9847b56ce89a58c91b98254cea26542.png

所以我的s.source_files = 'TDNIMKit/Classes/**/*',意思匹配Classes目录下的所有文件和文件夹
当然如果你没有文件夹嵌套可以写 s.source_files = 'TDNIMKit/Classes/*.{h,m}',意思匹配Classes下的任意.h .m文件
修改后

Pod::Spec.new do |s|
  #pod私有库名称
  s.name             = 'TDNIMKit'
  #pod私有库版本号
  s.version          = '0.1.0'
  #pod私有库概要
  s.summary          = 'striver custom NIMUIKit'
  #主要,最好能访问
  s.homepage         = 'https://github.com/458362366@qq.com/TDNIMKit'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  #开源协议
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  #开源作者
  s.author           = 'Striver'
  #源码地址,clone时候就需要使用这个地址跟版本拉取
  s.source           = { :git => 'https://github.com/458362366@qq.com/TDNIMKit.git', :tag =>'0.1.0' }
  #支持的系统版本
  s.ios.deployment_target = '8.0'
  #源码相对路径
  s.source_files = 'TDNIMKit/Classes/**/*'
end

然后打开工程podfile文件

use_frameworks!

platform :ios, '8.0'

target 'TDNIMKit_Example' do
  pod 'TDNIMKit', :path => '../'

  target 'TDNIMKit_Tests' do
    inherit! :search_paths

    
  end
end

写入TDNIMKit.podspec路径 如下

use_frameworks!

platform :ios, '8.0'

target 'TDNIMKit_Example' do
  pod 'TDNIMKit', :path => '../TDNIMKit.podspec'

  target 'TDNIMKit_Tests' do
    inherit! :search_paths

    
  end
end

尝试去执行以下pod install
pod install

再看工程发送了什么变化:
工程已经导入了源码

不要高兴太早,你会发现我们的NIMSDK呢,我们资源路径怎么加载呢????

其实也是跟加载s.source_files一样的:看一下framework文件夹下文件,framework 和.a文件

WeChatc941d565d93241d4a14b0a446616fc6e.png

继续回去编辑TDNIMKit.podspec增加如下代码

 #资源文件加载
  s.resources = 'TDNIMKit/Resources/*.*'
  #framework文件加载
  s.vendored_frameworks = '**/NIMSDK.framework'
  #.a静态库加载
  s.vendored_libraries = 'TDNIMKit/NIMSDK/Libs/*.a'

在pod install,完成后发现都导入了哈哈
资源文件,源码,framework都导入了
  1. 然后可以进行本地验证podspec文件是否正确了(一步步采坑指南);

cd 到TDNIMKit.podspec目录:执行pod lib lint,焦急的等待和期待!!!!!

果然会校验不通过,赶紧查看错误,经过一阵分析

 -> TDNIMKit (0.1.0)
    - WARN  | url: The URL (https://github.com/458362366@qq.com/TDNIMKit) is not reachable.
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - 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 and one is not being generated automatically. (in target 'App' from project 'App')
    - WARN  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:200:12: warning: parameter 'NIMMessage' not found in the function declaration [-Wdocumentation]
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:200:12: note: did you mean 'messages'?
    - WARN  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:210:12: warning: parameter 'NIMMessage' not found in the function declaration [-Wdocumentation]
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:210:12: note: did you mean 'message'?
    - WARN  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMConversationManagerProtocol.h:263:12: warning: parameter 'session' not found in the function declaration [-Wdocumentation]
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMConversationManagerProtocol.h:263:12: note: did you mean 'notify'?
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Global/NIMKitDependency.h:16:9: fatal error: 'M80AttributedLabel.h' file not found

[!] TDNIMKit did not pass validation, due to 1 error and 4 warnings.
You can use the `--no-clean` option to inspect any issue.

哦,原来是依赖了第三方库啊,我现在就去添加依赖。。继续编辑TDNIMKit.podspec
增加

#依赖的系统library
  s.libraries = 'sqlite3.0', 'z', 'c++'
  
  #依赖的第三方库
  s.dependency 'M80AttributedLabel', '~> 1.9.9'
  s.dependency 'FLAnimatedImage', '~> 1.0.12'
  s.dependency 'SDWebImage', '~> 4.2.2'
  s.dependency 'Toast', '~> 3.0'
  s.dependency 'TZImagePickerController', '~> 3.2.1'

再pod install

Example [master●●] % pod install
Analyzing dependencies
Downloading dependencies
Installing FLAnimatedImage (1.0.12)
Installing M80AttributedLabel (1.9.9)
Installing SDWebImage (4.2.3)
Installing TDNIMKit 0.1.0
Installing TZImagePickerController (3.2.7)
Installing Toast (3.1.0)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 6 total pods installed.

离成功又进了一步啊
高兴.jpg

继续验证podspec,很激动,这会肯定能验证通过

 -> TDNIMKit (0.1.0)
    - WARN  | url: The URL (https://github.com/458362366@qq.com/TDNIMKit) is not reachable.
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - 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 and one is not being generated automatically. (in target 'App' from project 'App')
    - WARN  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:200:12: warning: parameter 'NIMMessage' not found in the function declaration [-Wdocumentation]
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:200:12: note: did you mean 'messages'?
    - WARN  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:210:12: warning: parameter 'NIMMessage' not found in the function declaration [-Wdocumentation]
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:210:12: note: did you mean 'message'?
    - WARN  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMConversationManagerProtocol.h:263:12: warning: parameter 'session' not found in the function declaration [-Wdocumentation]
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMConversationManagerProtocol.h:263:12: note: did you mean 'notify'?
    - NOTE  | [iOS] xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Global/NIMKitDependency.h:16:9: fatal error: 'M80AttributedLabel.h' file not found

[!] TDNIMKit did not pass validation, due to 1 error and 4 warnings.
You can use the `--no-clean` option to inspect any issue.
TDNIMKit [master●●] % cd Example
Example [master●●] % pod install
Analyzing dependencies
Downloading dependencies
Installing FLAnimatedImage (1.0.12)
Installing M80AttributedLabel (1.9.9)
Installing SDWebImage (4.2.3)
Installing TDNIMKit 0.1.0
Installing TZImagePickerController (3.2.7)
Installing Toast (3.1.0)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 6 total pods installed.
Example [master●●] % cd ..
TDNIMKit [master●●] % pod lib lint

 -> TDNIMKit (0.1.0)
    - WARN  | url: The URL (https://github.com/458362366@qq.com/TDNIMKit) is not reachable.
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:183:17: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:184:18: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:200:17: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:201:18: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:218:25: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:219:26: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:237:29: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMTeamMemberCardViewController.m:238:30: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:82:100: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:124:71: warning: incompatible pointer types sending 'NIMMessage *' to parameter of type 'NSString * _Nonnull' [-Wincompatible-pointer-types]
    - NOTE  | xcodebuild:  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:147:37: note: passing argument to parameter 'aString' here
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:151:104: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:293:19: warning: unused variable 'index' [-Wunused-variable]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:308:100: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:347:15: warning: unused variable 'index' [-Wunused-variable]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionMsgDatasource.m:370:96: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:373:46: warning: undeclared selector 'sendImageMessage:' [-Wundeclared-selector]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:375:46: warning: undeclared selector 'sendImageMessage:' [-Wundeclared-selector]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:396:46: warning: undeclared selector 'sendImageMessage:' [-Wundeclared-selector]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:398:46: warning: undeclared selector 'sendImageMessage:' [-Wundeclared-selector]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:381:33: warning: unused variable 'message' [-Wunused-variable]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:365:25: warning: unused variable 'weakSelf' [-Wunused-variable]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:424:38: warning: undeclared selector 'sendImageMessage:' [-Wundeclared-selector]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:427:38: warning: undeclared selector 'sendImageMessage:' [-Wundeclared-selector]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:421:21: warning: unused variable 'message' [-Wunused-variable]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMSessionInteractorImpl.m:419:25: warning: unused variable 'weakSelf' [-Wunused-variable]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/View/SessionContentView/NIMSessionFileTransContentView.m:71:63: warning: format specifies type 'ssize_t' (aka 'long') but the argument has type 'long long' [-Wformat]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Common/NIMKitMediaFetcher.m:95:41: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Session/Object/NIMKitAudioCenter.m:65:13: warning: code will never be executed [-Wunreachable-code]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Input/NIMInputView.m:313:18: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Contact/NIMContactSelectViewController.m:140:13: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Contact/NIMContactSelectViewController.m:141:14: warning: block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior [-Wimplicit-retain-self]
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/Classes/Sections/Team/NIMAdvancedTeamCardViewController.m:1096:1: warning: implementing deprecated method [-Wdeprecated-implementations]
    - NOTE  | xcodebuild:  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h:316:1: note: method 'didRotateFromInterfaceOrientation:' declared here
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:200:12: warning: parameter 'NIMMessage' not found in the function declaration [-Wdocumentation]
    - NOTE  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:200:12: note: did you mean 'messages'?
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:210:12: warning: parameter 'NIMMessage' not found in the function declaration [-Wdocumentation]
    - NOTE  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMChatManagerProtocol.h:210:12: note: did you mean 'message'?
    - WARN  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMConversationManagerProtocol.h:263:12: warning: parameter 'session' not found in the function declaration [-Wdocumentation]
    - NOTE  | xcodebuild:  /Users/wangjiji/Desktop/podLibs/TDNIMKit/TDNIMKit/NIMSDK/NIMSDK.framework/Headers/NIMConversationManagerProtocol.h:263:12: note: did you mean 'notify'?
    - NOTE  | [iOS] xcodebuild:  ld: warning: instance method 'nim_drawImageWithSize:' in category from /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/TDNIMKit.build/Objects-normal/x86_64/UIImage+NIMKit.o conflicts with same method from another category
    - NOTE  | [iOS] xcodebuild:  ld: warning: instance method 'nim_drawImageWithSize:' in category from /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/TDNIMKit.build/Objects-normal/i386/UIImage+NIMKit.o conflicts with same method from another category
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitDependency.h:22:9: error: include of non-modular header inside framework module 'TDNIMKit.NIMKitDependency': '/Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/SDWebImage/SDWebImage.framework/Headers/SDWebImageCompat.h' [-Werror,-Wnon-modular-include-in-framework-module]
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitDependency.h:29:9: error: include of non-modular header inside framework module 'TDNIMKit.NIMKitDependency': '/Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/SDWebImage/SDWebImage.framework/Headers/SDWebImageManager.h' [-Werror,-Wnon-modular-include-in-framework-module]
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitDependency.h:30:9: error: include of non-modular header inside framework module 'TDNIMKit.NIMKitDependency': '/Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/SDWebImage/SDWebImage.framework/Headers/UIView+WebCacheOperation.h' [-Werror,-Wnon-modular-include-in-framework-module]
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitDependency.h:31:9: error: include of non-modular header inside framework module 'TDNIMKit.NIMKitDependency': '/Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/SDWebImage/SDWebImage.framework/Headers/UIView+WebCache.h' [-Werror,-Wnon-modular-include-in-framework-module]
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitDependency.h:38:9: error: include of non-modular header inside framework module 'TDNIMKit.NIMKitDependency': '/Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/Toast/Toast.framework/Headers/UIView+Toast.h' [-Werror,-Wnon-modular-include-in-framework-module]
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitKeyboardInfo.h:11:1: error: duplicate interface definition for class 'NIMKitKeyboardInfo'
    - NOTE  | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitKeyboard.h:11:12: note: previous definition is here
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitKeyboardInfo.h:14:47: error: property has a previous declaration
    - NOTE  | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitKeyboard.h:14:47: note: property declared here
    - ERROR | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitKeyboardInfo.h:17:47: error: property has a previous declaration
    - NOTE  | xcodebuild:  /Users/wangjiji/Library/Developer/Xcode/DerivedData/App-gjkqwvanivaxhccdvgxqguipgjmq/Build/Products/Release-iphonesimulator/TDNIMKit/TDNIMKit.framework/Headers/NIMKitKeyboard.h:17:47: note: property declared here
    - NOTE  | xcodebuild:  /var/folders/sj/46yckf194p37wvdhmfh0j2_m0000gn/T/CocoaPods-Lint-20191119-1941-1d76rqs-TDNIMKit/App/main.m:3:9: fatal error: could not build module 'TDNIMKit'
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

[!] TDNIMKit did not pass validation, due to 9 errors and 36 warnings.
You can use the `--no-clean` option to inspect any issue.

卧槽,无情

咋肥事??错误更多了!我配置好证书,build工程居然是可以的。那就是我验证文件的姿势有问题!原来是我们依赖了.a文件,不影响使用但是验证需要指明。验证时候需要 --use-libraries,并且忽略警告
pod lib lint --use-libraries --allow-warnings
嘿嘿嘿,TDNIMKit passed validation.这次果然ok了。这只是说明我们本地的podspec是校验通过了的,还需要验证远程podsepec校验。

  1. 将修改好的模板工程上传到github托管
  • 先创建空仓库
    *然后代码提交到仓库
echo "# TDNIMKit" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:strivever/TDNIMKit.git
git push -u origin master
  • 打上tag,需要跟podspec文件中指定的tag一致 默认这里没有问题。将podsepec中的 source填入仓库地址
    上传到仓库记得看一下远程仓库资源是否被同步上去了,不然一会校验会出现资源匹配不到。

  • 远程仓库验证
    pod spec lint --use-libraries --allow-warnings验证可能很漫长,可以增加 --verbose查看日志

居然有报错RPC failed; curl 18 transfer closed with outstanding read data remaining
solution.1 将source换成ssh地址试一下
solution.2 git config http.postBuffer 524288000

然后校验通过了 GOOD!

4. 发布私有库,关联到 TDNIMKitSpec文件

pod repo push TDNIMKitSpec TDNIMKit.podspec --use-libraries --allow-warnings --verbose推送成功

pod命令 pod repo push 【本地spec文件夹名称】【需要发布的.podspec文件】--use-libraries --allow-warnings --verbose

发生错误:

 $ /usr/local/bin/git -C /Users/wangjiji/.cocoapods/repos/TDNIMKitSpec pull
  Your configuration specifies to merge with the ref 'refs/heads/master'
  from the remote, but no such ref was fetched.
[!] /usr/local/bin/git -C /Users/wangjiji/.cocoapods/repos/TDNIMKitSpec pull

Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.

solution:因为我们的spec索引库为空的,是不允许我们提交的,此时添加README.md文件,并提交到仓库。也可以创建索引库时候勾上自动创建README.md文件

touch README.md
git add README.md 
git commit -m 'first commit'
git push origin master

然后再回到模板工程推一遍即可,此时成功啦!
发布私有库成功

查看一下本地和远程应该都有了podspec

5.测试一下

打开一个cocoapods管理的项目,添加该私有库

source 'https://github.com/CocoaPods/Specs.git'
source 'git@github.com:strivever/TDNIMKitSpec.git'
platform :ios,'8.0'
workspace 'BOOK'
abstract_target 'CommonPods' do
pod 'YYKit', '~> 1.0.9'
pod 'TDNIMKit', '0.1.0'
  target 'GCYSColledge' do
    project 'GCYSColledge/GCYSColledge.xcodeproj'
  end
  
  target 'BOOK' do
    project 'BOOK.xcodeproj'
  end
end

跟其它三方没啥区别,只是需要指定私有Spec源,pod install --repo-update --verbose等待安装:

StriVever@StrivEver ~ ±master⚡ » cd /Users/wangjiji/Desktop/BOOK           1 ↵
StriVever@StrivEver ~/Desktop/BOOK ±master⚡ » pod install --repo-update --verbose
  Preparing

Updating local specs repositories
  CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local
  because checking is only perfomed in repo update

Updating spec repo `master`
  $ /usr/local/bin/git -C /Users/wangjiji/.cocoapods/repos/master fetch origin
  --progress

6.我们发现pod install 私有库之后,所有的源码文件全部在一个文件夹里。如果需要文件夹嵌套需要使用 subspec方式实现子文件夹嵌套:效果如下图:

文件夹嵌套

如下这种形式,注意当子文件夹里需要依赖其他文件夹,需要指明 dependency 不然会报错,找不到.h文件。这个路径也是相对路径,路径到依赖文件所在文件夹即可,说明你需要依赖其中一个子模块。我的理解subspec其实是独立功能的子模块,不是单单为了放入文件夹中管理,这些子模块也可以被独立集成进项目中,所以需要指明依赖cacheHelper.dependency 'TDNetworkKit/TDNetworkConfiguration'

  s.subspec 'TDCacheHelper'do |cacheHelper|
     cacheHelper.source_files = 'TDNetworkKit/Classes/TDCacheHelper/*.{h,m}'
      cacheHelper.public_header_files = "TDNetworkKit/Classes/TDCacheHelper/*.h"
      cacheHelper.dependency  'TDNetworkKit/TDNetworkConfiguration'
  end

7.编辑我们的README.md小尾巴

如下图:
README小尾巴

对应代码,#代表跳转链接,这个链接只能是该仓库内部链接,我没有写

# TDNetworkKit
[![CI Status](https://img.shields.io/badge/build-pass-orange.svg)](#)
[![Version](https://img.shields.io/badge/Version-0.1.0-blue.svg)](#)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](#)
[![Platform](https://img.shields.io/badge/Platform-iOS8.0-red.svg)](#)

图标文字和颜色格式都是可以设置的:
https://img.shields.io/badge/build-pass-orange.svg
https://img.shields.io/badge/【前半部分文字】-【后半部分文字】-【颜色,英文,16进制都行】.svg

demo点这里

参考:
https://juejin.im/post/5c796afbf265da2db3056c85

https://juejin.im/post/5ba8e3c95188255c581aacbd

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,324评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,356评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,328评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,147评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,160评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,115评论 1 296
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,025评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,867评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,307评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,528评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,688评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,409评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,001评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,657评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,811评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,685评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,573评论 2 353

推荐阅读更多精彩内容