iOSiOS精学选辑

iOS 远程私有库

2017-04-12  本文已影响375人  AKyS佐毅
WechatIMG13.jpeg

一: 创建pod项目工程文件

  pod lib create ConsultantBase  ##ConsultantBase  你要创建的pod名字
1.png

之后生成的文件目录结构是这样的

2.png

我们需要需要将replaceMe替换为我们自己的文件,效果图如下:


WechatIMG14.jpeg 屏幕快照 2017-04-12 下午3.14.18.png

然后进入Example文件夹执行pod update命令,再打开项目工程可以看到,刚刚添加的组件已经在Pods子工程下Development ConsultantBase/ConsultantBase中了。

二: 修改ConsultantBase.podspec文件,和远程的链接关联

```
  Pod::Spec.new do |s|
  s.name             = 'ConsultantBase'
  s.version          = '0.1.0'
  s.summary          = 'ConsultantBase.'
  s.description      = <<-DESC
      Add long description of the pod here.
                   DESC

  s.homepage         =     'https://coding.net/u/Mikes/p/ConsultantSpecs'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Kenvin' => 'yaoyj@oriental-finance.com' }
  s.source           = { :git => 'https://git.coding.net/Mikes/ConsultantBase.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
  s.ios.deployment_target = '8.0'
  s.source_files = 'ConsultantBase/Classes/**/*'

  # s.resource_bundles = {
     #   'ConsultantBase' => ['ConsultantBase/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end
```

二: 本地库和远程关联

在远端添加远端仓库


WechatIMG15.jpeg
git add .
git commit -m "Initial ConsultantBase "
#添加远端仓库
git remote add origin https://git.coding.net/Mikes/xxxx.git  
#推送到远端仓库
git push origin master

对本地库添加tag标签

 git tag 0.1.0
git push --tag

之后对本地库进行校验

   pod spec lint --allow-warnings

如果成功,返回:


 -> ConsultantBase (0.1.0)
    - WARN  | [iOS] xcodebuild:  ConsultantBase/ConsultantBase/Classes/Category/UITextView+SMKLimitTips.m:153:73: warning: values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat]
Analyzed 1 podspec.
ConsultantBase.podspec passed validation.

如果失败

~:ConsultantBase Kenvin$ pod lib lint

-> ConsultantBase (0.1.0)
   - WARN  | [iOS] xcodebuild:  /Users/Kenvin/remoteLib/ConsultantBase/ConsultantBase/Classes/Category/UITextView+SMKLimitTips.m:153:73: warning: values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat]

[!] ConsultantBase did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
   `echo "2.3" > .swift-version`.
You can use the `--no-clean` option to inspect any issue.

解决方案是:

~:ConsultantBase Kenvin$ echo "2.3" > .swift-version

三: 将pod组建和自己建立的pod索引库 xxSpecs 关联

   pod repo add ConsultantSpecs     https://git.coding.net/Mikes/xxxxSpecs.git

执行:

    pod repo

结果:


artsy
- Type: git (master)
- URL:  https://github.com/Artsy/Specs.git
- Path: /Users/Kenvin/.cocoapods/repos/artsy

ConsultantSpecs
- Type: git (master)
- URL:  https://git.coding.net/Mikes/ConsultantSpecs.git
- Path: /Users/Kenvin/.cocoapods/repos/ConsultantSpecs

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/Kenvin/.cocoapods/repos/master

3 repos

四:向Spec Repo提交podspec文件

pod  repo push ConsultantSpecs ConsultantBase.podspec

结果:

WechatIMG16.jpeg

五:使用制作好的Pod

在正式项目的Podfile 里添加私有Spec Repo

source 'https://git.coding.net/Mikes/ConsultantSpecs.git' 
pod 'ConsultantBase', '~> 0.1.0'

然后执行pod update,更新库依赖,然后打开项目可以看到,我们自己的库文件已经出现在Pods子项目中的Pods子目录下了,而不再是Development Pods。

上一篇下一篇

猜你喜欢

热点阅读