iOS组件化 Cocoapods管理自己的库

github 创建仓库

new 一个 repository

创建仓库

clone 到本地 并初始化工程

创建.podspec文件

$pod spec create 工程名
创建.podspec文件

文本编辑打开.podspec文件

  Pod::Spec.new do |s|

  s.name         = "RJMyPod"
  s.version      = "0.0.1"
  s.summary      = "A iOS Fast integration of custom classifications, macro definitions and tool classes"
  s.homepage     = "https://github.com/Jack424/RJMyPod.git"
  s.license      = "MIT"
  s.author       = { "Jack_Gu" => "gu_ruijie@163.com" }
  s.platform     = :ios, "9.0"
  s.source       = { :git => "https://github.com/Jack424/RJMyPod.git", :tag => s.version}
  s.source_files = "RJMyPod/RJMyPod/MyPod/*.{h,m}"
  s.requires_arc = true
 s.resources    = "RJCategoryTool/RJCategoryTool/RJCategoryTool/Resource/*.{png,xib,nib,bundle,json}"
end
  s.dependency 'Masonry'
  
  # s.resources    = 'PhotoBrowser/resource/*.{png,xib,nib,bundle}'
  # s.frameworks   = 'UIKit','Photos','PhotosUI'
  # s.dependency 'UMengUShare/Social/ReducedWeChat', '~> 6.4.8.2'
end
  s.name          :工程名
  s.version       :版本号
  s.summary       :简介概述
  s.homepage      :github项目网页 
  s.license       :授权许可文件 
  s.author        :代码作者
  s.platform      :支持最低的版本号
  s.source        :git代码下载地址
  s.source_files  :!重要 ! 你要传到cocoapods的文件内容  
  s.resources     :资源文件,没有可忽略
  s.requires_arc  :是否是ARC 

注意:s.source_files 下层级目录一定是podspec所在层级的文件名开始到你要上传的文件目录为止 *.{h,m} 表示匹配所有以.h和.m结尾的文件 ** 表示匹配所有子目录 若所上传文件夹有子级文件则在文件名后追加 **/*.{h,m}

解决[-Werror,-Wnon-modular-include-in-framework-module]错误, .h文件中引用第三方库 #import <Masonry/Masonry.h>,使用尖括号引用

上传过程中遇到问题就细心检查一下

$ git add --all
$ git commit -m "操作内容"
$ git tag "0.0.1"
$ git push --tags
$ git push origin master

验证上传是否合法

$ pod spec lint --allow-warnings
 -> RJMyPod (0.0.1)
    - 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')

Analyzed 1 podspec.

RJMyPod.podspec passed validation.

出现成功提示后就trunk上传,如果没有没有注册过需要首次注册

$ pod trunk register 邮箱 '用户名' --description='描述一下下'

邮箱及用户名以你GitHub的为准
提交指令后需要去邮箱验证,点击或复制邮箱邮件内的链接会显示

邮件内容

自我验证

$ pod trunk me
- Name:     Jack424
  - Email:    gu_ruijie@163.com
  - Since:    September 18th, 2017 21:46
  - Pods:
    - GRJKit
    - GRJMITKit
    - RJCategoryTool
  - Sessions:
    - September 18th, 2017 21:46 - January 25th, 2018 01:13. IP: 120.236.169.38
    Description: macbook pro
    - February 14th, 20:57       -         June 23rd, 05:36. IP: 27.115.4.10   
    Description: 描述一下下
  • 报错及解决
$ pod trunk me
[!] Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.

$ pod trunk register 'gu_ruijie@163.com' 'Jack424' --description='mac pro'
// 然后去邮箱操作一下即可
/*
Please confirm your CocoaPods session by clicking the following link:

    https://trunk.cocoapods.org/sessions/verify/**************

If you did not request this you do not need to take any further action.
*/

提交

$ pod trunk push --allow-warnings
上传pod成功

使用一下

  pod 'RJMyPod'

$ pod install
试一试

如果报错:- ERROR | [iOS] unknown: Encountered an unknown error (Malformed version number string ) during validation.

$ sudo gem install -n /usr/local/bin cocoapods

Password:
Fetching: cocoapods-core-1.7.1.gem (100%)
Successfully installed cocoapods-core-1.7.1
Fetching: cocoapods-deintegrate-1.0.4.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.4
Fetching: xcodeproj-1.9.0.gem (100%)
Successfully installed xcodeproj-1.9.0
Fetching: fourflusher-2.3.0.gem (100%)
Successfully installed fourflusher-2.3.0
... ...

ZLPhotoBrowser 使用 SDWebImage 报错
打印错误信息

pod spec lint RJCategoryTool.podspec --verbose 
- 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
- ERROR | [iOS] xcodebuild:  ZLPhotoBrowser/ZLPhotoBrowser/PhotoBrowser/ZLBigImageCell.m:504:77: error: use of undeclared identifier 'SDWebImageProgressiveDownload'; did you mean 'SDWebImageProgressiveLoad'?
- NOTE  | [iOS] xcodebuild:  SDWebImage/SDWebImage/Core/SDWebImageDefine.h:69:5: note: 'SDWebImageProgressiveLoad' declared here

[!] The spec did not pass validation, due to 2 errors.

ZLPhotoBrowser更新日志
3.0.3: 依赖库SDWebImage升级为5.0.2以上

● 3.0.6: 添加选中图片显示index功能; 新增(及修改)部分颜色api,方便修改框架内部颜色; 修改框架默认风格为微信的风格; 压缩图片资源;
● 3.0.5: 预览快速选择界面文字颜色支持自定义; 编辑界面按钮增大; 解决录制视频超过10s没有声音的bug;
● 3.0.4: 添加视频选择最大最小个数限制; 解决网络gif图片无法播放的bug; fix已知bug;
● 3.0.3: 依赖库SDWebImage升级为5.0.2以上; 解决图片浏览器关闭时取消所有sd图片请求的bug; 支持直接调用相机;
● 3.0.0: 压缩bundle内图片; 支持直接选择iCloud照片,并添加解析图片超时时间属性;
● 3.0.0: 支持carthage; 去除GPUImage滤镜;
● 2.7.8: 添加iCloud图片加载进度条,支持iCloud视频播放;
● 2.7.6: 预览大图界面支持precent情况下的下拉返回;
● 2.7.5: 编辑图片支持自定义工具类型; bug fixed;
● 2.7.4: 横滑大图界面添加下拉返回; 不允许录制视频时候不请求麦克风权限;
● 2.7.1: 支持自定义导航返回按钮图片;
● 2.7.0: 图片资源加上前缀,解决9.0无法选择图片问题; 
● 2.6.9: 重构编辑图片功能,添加滤镜;
● 2.6.7: 优化视频编辑界面,极大减少进入时的等待时间;
● 2.6.6: Fix #216; 新增隐藏裁剪图片界面比例工具条功能;
● 2.6.5: 新增隐藏"已隐藏"照片及相册的功能; Fix #221, 优化预览网络图片/视频时根据url后缀判断的类型方式;



报错

[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

$ pod update
Update all pods
Updating local specs repositories
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

$ pod repo update master --verbose
Updating spec repo `master`
  $ /usr/bin/git -C /Users/jintian/.cocoapods/repos/master fetch origin --progress
  remote: Enumerating objects: 12756, done.        
  remote: Counting objects: 100% (12756/12756), done.        
  remote: Compressing objects: 100% (440/440), done.        
  remote: Total 33049 (delta 12458), reused 12299 (delta 12299), pack-reused 20293        
  Receiving objects: 100% (33049/33049), 3.68 MiB | 85.00 KiB/s, done.
  Resolving deltas: 100% (22711/22711), completed with 3716 local objects.
  From https://github.com/CocoaPods/Specs
     279b00360ea..4826f4cad15  master     -> origin/master
  $ /usr/bin/git -C /Users/jintian/.cocoapods/repos/master rev-parse --abbrev-ref HEAD
  master
  $ /usr/bin/git -C /Users/jintian/.cocoapods/repos/master reset --hard origin/master
  Checking out files: 100% (3441/3441), done.
  HEAD is now at 4826f4cad15 [Add] QBRouter 0.0.5

$ pod update
Update all pods
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing AFNetworking 4.0.1 (was 3.2.1 and source changed to `https://github.com/CocoaPods/Specs.git` from `trunk`)
Installing AlipaySDK-iOS 15.7.4 (was 15.6.8 and source changed to `https://github.com/CocoaPods/Specs.git` from `trunk`)
Installing MBProgressHUD 1.2.0 (was 1.1.0 and source changed to `https://github.com/CocoaPods/Specs.git` from `trunk`)
Installing MJRefresh 3.4.1 (was 3.2.2 and source changed to `https://github.com/CocoaPods/Specs.git` from `trunk`)
Installing WechatOpenSDK 1.8.7.1 (was 1.8.6 and source changed to `https://github.com/CocoaPods/Specs.git` from `trunk`)
Generating Pods project
Integrating client project
Pod installation complete! There are 17 dependencies from the Podfile and 17 total pods installed.

[!] Automatically assigning platform `iOS` with version `10.0` on target `RJCategoryTool` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

[!] CDN: trunk URL couldn't be downloaded:

$ pod search AFNetworking
[!] CDN: trunk Repo update failed - 2 error(s):
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/a/7/5/AFNetworking/4.0.0/AFNetworking.podspec.json Response: Couldn't connect to server
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/a/7/5/AFNetworking/4.0.1/AFNetworking.podspec.json Response: Couldn't connect to server

$ pod repo remove trunk

- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use--verbosefor more information.

    - 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
    ...
    [!] The spec did not pass validation, due to 1 error.
$ pod spec lint RJCategoryTool.podspec --verbose //打印错误信息

ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices

$ pod trunk push  --allow-warnings 
$ pod trunk push  --allow-warnings --use-libraries
Updating spec repo `master`

CocoaPods 1.8.0 is available.
To update use: `sudo gem install cocoapods`

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.8.0

Validating podspec
 -> RJCategoryTool (0.5.5)
    - ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices

xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
) during validation.

[!] The spec did not pass validation, due to 1 error.
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Password:
$ pod trunk push RJCategoryTool.podspec --allow-warnings --use-libraries
Updating spec repo `master`

CocoaPods 1.8.0 is available.
To update use: `sudo gem install cocoapods`

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.8.0

Validating podspec
 -> RJCategoryTool (0.5.5)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
...

...
Updating spec repo `master`

CocoaPods 1.8.0 is available.
To update use: `sudo gem install cocoapods`

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.8.0


--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  RJCategoryTool (0.5.5) successfully published
 📅  September 27th, 04:59
 🌎  https://cocoapods.org/pods/RJCategoryTool
 👍  Tell your friends!
--------------------------------------------------------------------------------

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