iOS组件化(基于Cocoapods)-简单使用

2017-06-30  本文已影响421人  manajay

注册 trunk

pod trunk register xxxx@gmail.com manajay

创建本地私有库

更改本次的版本描述

验证本地的组件库是否有效

pod lib lint

测试一

pod lib lint --no-clean LJNetwork.podspec

 -> LJNetwork (1.0.0)
    - ERROR | attributes: Missing required attribute `summary`.
    - ERROR | [iOS] unknown: Encountered an unknown error (The `LJNetwork` pod failed to validate due to 1 error:
    - ERROR | attributes: Missing required attribute `summary`.

) during validation.

Pods workspace available at `/var/folders/86/kvr1rbk53zgb0xpkljyv2vn80000gn/T/CocoaPods-Lint-20180308-31173-4h194x-LJNetwork/App.xcworkspace` for inspection.

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

修改 summary
测试二

pod lib lint --no-clean LJNetwork.podspec

 -> LJNetwork (1.0.0)
    - WARN  | [iOS] swift: The validator used Swift 3.2 by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_version` attribute in your podspec. Note that usage of the `--swift-version` parameter or a `.swift-version` file is now deprecated.

Pods workspace available at `/var/folders/86/kvr1rbk53zgb0xpkljyv2vn80000gn/T/CocoaPods-Lint-20180308-31243-i7bisy-LJNetwork/App.xcworkspace` for inspection.
[!] LJNetwork did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).

注意如果出现WARN字样 可以使用pod repo push XXXSpec xxx.podspec --allow-warnings 忽略警告

测试三

pod lib lint --no-clean --allow-warnings  LJNetwork.podspec

 -> LJNetwork

 -> LJNetwork (1.0.0)
    - WARN  | xcodebuild:  ReachabilitySwift/Reachability/Reachability.swift:95:42: warning: plaform condition appears to be testing for simulator environment; use 'targetEnvironment(simulator)' instead

Pods workspace available at `/var/folders/86/kvr1rbk53zgb0xpkljyv2vn80000gn/T/CocoaPods-Lint-20180308-32416-1hp85wj-LJNetwork/App.xcworkspace` for inspection.

LJNetwork passed validation.

关联远程库, 设置tag 并推送到 远程库

git tag xxx
git push -u origin master // 首次推送
git push --tags

创建自己的私有远程管理库

私有库, 经常会有提示错误 The project you were looking for could not be found. 原因的访问权限问题
在你的pod 库的podspec 文件中, 编辑 s.sourceurl 链接前要加username
"The project you were looking for could not be found."

推送组件的 podspec文件到自己的私有远程管理库

pod trunk --allow-warnings push LJNetwork.podspec
Updating spec repo `master`
Validating podspec
 -> LJNetwork (1.0.0)
    - WARN  | xcodebuild:  ReachabilitySwift/Reachability/Reachability.swift:95:42: warning: plaform condition appears to be testing for simulator environment; use 'targetEnvironment(simulator)' instead

Updating spec repo `master`

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

 🚀  LJNetwork (1.0.0) successfully published
 📅  March 8th, 02:04
 🌎  https://cocoapods.org/pods/LJNetwork
 👍  Tell your friends!

使用 私有组件

搜索自己的私有库组件 pod search

# 表示先去找私有,在找公有
source 'https://git.XXX/XXXSpec.git'
source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

pod 'xxx'

如果遇到 The project you were looking for could not be found. 类似👆的权限问题, 这里只需要将 Podfile 中的私有 pod source 前面加username@ 即可

# 表示先去找私有,在找公有
source 'https://username@git.XXX/XXXSpec.git'
source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

pod 'xxx'

组件升级

pod repo push XXXSpec xxx.podspec --allow-warnings

pod update --no-repo-update

<补充> Cocoapods公有仓库推送

登录

pod trunk register mailname@gmail.com 'username' --description='xxxx'
[!] Please verify the session by clicking the link in the verification email that has been sent to manajay.dlj@gmail.com

用于已有用户的登录 获取session

  - Name:     Manajay
  - Email:    manajay.dlj@gmail.com
  - Since:    xxxx xxth, xxxx xx:xx
  - Pods:
    - NJAlertView
    - LJNetwork
  - Sessions:
    - August xxth, xxxx xx:xx  - December xxth, xxx xx:xx. IP: xxxxx  Description: custom alertView
    - June xxth, xxxx xx:xx   -  November xxth, xxxx xx:xx. IP: xxxx
    - August xxth, xxx xx:xx - December xxth, xxxx xx:xx. IP: xxxxxxx
    - March xxth, xx:xx        -          July xxth, xx:xx. IP: xxxxx Description: xx xx

如果想将私有库,打包成静态库.a或者.framework的话, 就需要``

// 打包.a           注意:  `--force`  是指强制覆盖
pod package XXX.podspec --library --force
// 打包.framework
pod package XXX.podspec --force 
// 注意 静态库打包时, 默认打包的是 default_subspec的              

用CocoaPods开发并打包静态库
私有pod创建进阶--如何通过pod管理静态库

链接

上一篇 下一篇

猜你喜欢

热点阅读