组件化iOS面试题iOS项目

iOS CocoaPods私有库

2019-02-21  本文已影响0人  konglei
远程私有库工作流程

远程私有库就可以方便的解决以上的问题,制作远程私有库分为以下几个步骤:

使用模板 pod lib create 生成一个本地私有库

#创建命令
pod lib create PrivateHelloWorld
# 选择编程语言
What language do you want to use?? [ Swift / ObjC ]
> Objc  

# 在你的项目中是否创建一个demo工程,为了方便测试,我选择了Yes
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?
 > QIN

操作结果如下:

$ pod lib create QinTestSpec
Cloning `https://github.com/CocoaPods/pod-template.git` into `QinTestSpec`.
Configuring QinTestSpec template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


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?
 > QIN
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

Running pod install on your new library.

Analyzing dependencies
Fetching podspec for `QinTestSpec` from `../`
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing QinTestSpec (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `QinTestSpec.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'QinTestSpec/Example/QinTestSpec.xcworkspace'

创建完项目会自动打开,项目目录结构如下:

.
├── QinTestSpec
│   ├── Assets
│   └── Classes
│       └── ReplaceMe.m
├── QinTestSpec.podspec
├── Example
├── LICENSE
├── README.md
└── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj

在replaceme处替换为自己的代码

在Example 目录下 pod install 即可使用

image.png

可以移除这三个文件后 pod install

kongxs:QinTestSpec aladin$ cd /Users/aladin/Documents/QinTestSpec/QinTestSpec/Example 
kongxs:Example aladin$ pod install
Analyzing dependencies
Fetching podspec for `QinTestSpec` from `../`
Downloading dependencies
Using FBSnapshotTestCase (2.1.4)
Installing QinTestSpec 0.1.0
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

编辑CocoaPods的配置文件 -- QinTestSpec.podspec

Pod::Spec.new do |s|
  s.name             = 'QinTestSpec'
  s.version          = '0.1.0'
  s.summary          = 'A short description of QinTestSpec.'

# 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/kongCoco/QinTestSpec'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  # 作者
  s.author           = { 'kongxs' => '13780900915@163.com' }
  # git地址
  s.source           = { :git => 'https://github.com/kongCoco/QinTestSpec.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'QinTestSpec/Classes/**/*'
  
  # s.resource_bundles = {
  #   'QinTestSpec' => ['QinTestSpec/Assets/*.png']
  # }

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

验证pod配置文件

kongxs:QinTestSpec aladin$ pod lib lint --allow-warnings

 -> QinTestSpec (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/kongCoco/QinTestSpec) is not reachable.
    - 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')

QinTestSpec passed validation.
# 通过

项目发布

终端移到该项目文件下执行git的相关命令

tag 0.0.1

#添加远程地址,即上面创建git项目的地址
kongxs:QinTestSpec aladin$ git remote add origin https://github.com/kongCoco/QinTestSpec.git
# 添加文件
kongxs:QinTestSpec aladin$ git add .
# 提交本地,并写描述
kongxs:QinTestSpec aladin$ git commit -a -m "第一次提交 版本为0.1.0"
[master 537a92c] 第一次提交 版本为0.1.0
 60 files changed, 3860 insertions(+), 6 deletions(-)
 create mode 100644 Example/Podfile.lock
...
kongxs:QinTestSpec aladin$ git pull origin maste
fatal: Could not find remote ref maste
kongxs:QinTestSpec aladin$ git pull origin master --allow-unrelated-histories
warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/kongCoco/QinTestSpec
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Auto-merging LICENSE
CONFLICT (add/add): Merge conflict in LICENSE
Automatic merge failed; fix conflicts and then commit the result.
# 项目中解决冲突
kongxs:QinTestSpec aladin$ git commit -a -m "merge"
[master d527475] merge
kongxs:QinTestSpec aladin$ git pull origin master --allow-unrelated-histories
From https://github.com/kongCoco/QinTestSpec
 * branch            master     -> FETCH_HEAD
Already up to date.
# 推送到git项目的master分支上
kongxs:QinTestSpec aladin$ git push origin master
Counting objects: 117, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (108/108), done.
Writing objects: 100% (117/117), 53.52 KiB '|' 3.34 MiB/s, done.
Total 117 (delta 28), reused 0 (delta 0)
remote: Resolving deltas: 100% (28/28), completed with 1 local object.
To https://github.com/kongCoco/QinTestSpec.git
   05448c2..d527475  master -> master.
# 提交版本号
kongxs:QinTestSpec aladin$ git tag '0.1.0'
# 推送tag到远端仓库
kongxs:QinTestSpec aladin$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/kongCoco/QinTestSpec.git
 * [new tag]         0.1.0 -> 0.1.0

在gitHub创建git私有库

在终端执行Specs创建命令

kongxs:QinTestSpecDemo aladin$ pod repo add QinTestSpec https://github.com/kongCoco/QinTestSpec.git
Cloning spec repo `QinTestSpec` from `https://github.com/kongCoco/QinTestSpec.git`
Username for 'https://github.com': Username
Password for 'https://13780900915@163.com@github.com': Password

验证远端

kongxs:QinTestSpec aladin$ pod spec lint --allow-warnings

 -> QinTestSpec (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/kongCoco/QinTestSpec) is not reachable.
    - 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.

QinTestSpec.podspec passed validation.

现在,我们可以直接发布了

QinTestSpec是刚才上面添加的管理库名字
QinTestSpec.podspec是QinTestSpec项目里面后缀为podspec的文件名

kongxs:QinTestSpec aladin$ pod repo push QinTestSpec QinTestSpec.podspec --allow-warnings

Validating spec
 -> QinTestSpec (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/kongCoco/QinTestSpec) is not reachable.
    - 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')

Updating the 'QinTestSpec' repo
...

Adding the spec to the `QinTestSpec' repo

 - [Update] QinTestSpec (0.1.0)

Pushing the `QinTestSpec' repo

发布成功后,我们可以去git看看QinTestSpec的git项目有没有提交成功

success

参考

你真的会用 CocoaPods 吗?
IOS创建CocoaPods私有库
CocoaPods私有库创建与使用
使用Cocoapods创建私有库
你真的会用 CocoaPods 吗?

上一篇 下一篇

猜你喜欢

热点阅读