1,CocoaPods的簡單介紹以及使用
我這篇文章主要介紹如何將項目發布到CocoaPods上,安裝以及簡單實用我介紹幾個博客給大家。其中如果你遇到問題還是可以看下面的評論,如果實在不行stackoverflow一定能夠幫你解決。
首先是安裝以及簡單使用的博客:http://www.lxweimin.com/p/f5536485e3a0
其次是更新的博客:http://www.lxweimin.com/p/f5536485e3a0
最后我貼上我這個工程寫的的pod文件
source 'https://git.coding.net/hging/Specs.git'
platform :ios, '8.0'
inhibit_all_warnings!
target 'LLToast’ do
pod 'pop', '~> 1.0'
end
2,將自己的代碼發布到CocoaPods上
2.1 創建自己的github倉庫
CocoaPods都托管在github上(官方鏈接),所有的Pods依賴庫都依賴github,因此我們需要創建一個github,如圖
2.2將倉庫clone到本地
git clone https://github.com/lilianmao/LLToast
2.3向git倉庫添加創建Pods依賴庫的所有文件
2.3.1本地倉庫更新
首先將自己寫的框架復制到你創建的本地倉庫里,這里我直接賦值粘貼了,這里大家最好如下圖放置,因為這樣可以方便別人看懂你的項目,一個license,一個readme,一個你的podspec文件(這個文件的生成我在后面會講的),一個項目的demo,另一個是你的框架。
2.3.2創建podspec文件,并且重寫這個文件
創建這個文件
pod spec create LLToast
修改podspec文件
#
# Be sure to run `pod spec lint LLToast.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#
s.name = "LLToast"
s.version = "1.0.0"
s.summary = "A simple LLToast."
# 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
This is a simple toast.
這是一個簡單的toast
DESC
s.homepage = "https://github.com/lilianmao/LLToast"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#
s.license = "MIT"
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
s.author = { "lilin" => "1911932429@qq.com" }
# Or just: s.author = "lilin"
# s.authors = { "lilin" => "1911932429@qq.com" }
# s.social_media_url = "http://twitter.com/lilin"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#
# s.platform = :ios
s.platform = :ios, '8.0'
# When using multiple platforms
# s.ios.deployment_target = "8.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
s.source = { :git => "https://github.com/lilianmao/LLToast.git", :tag => "#{s.version}" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#
s.source_files = "LLToast/*"
# s.exclude_files = "LLToast/*"
# s.public_header_files = "Classes/**/*.h"
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#
# s.resource = "icon.png"
# s.resources = "Resources/*.png"
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
# s.framework = "SomeFramework"
# s.frameworks = "SomeFramework", "AnotherFramework"
# s.library = "iconv"
# s.libraries = "iconv", "xml2"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.
# s.requires_arc = true
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
s.dependency "pop", "~> 1.0"
end
這里我介紹幾個要改的屬性:
我先強調一下這個文件如果你需要該屬性,必須去掉前面的#,不然是無效的,我被這個坑了好一會兒。(后來才知道這個ruby語言的注釋)
s.version 一般情況下改為1.0.0
s.description 寫一個對于你的框架代碼的簡單注釋
s.homepage 寫一個你項目對于的github主頁
s.license 我寫的是MIT(雖然我也沒懂為啥寫這個)
s.platform 我寫的是8.0的系統,可以默認,但是你得保持對于你寫的系統的兼容性。
s.source 這個必須指向你的github項目的地址
s.source_files 這里我已開始改錯了,前面有個#,應該是注釋的意思,你要把注釋去掉,然后寫上你的框架代碼的位置,這里我是當前文件夾->LLToast下面的所有文件。
s.dependency 你這個框架依賴的庫,我依賴了pop框架。
最后用一句代碼檢查你的pod有沒有問題(第二句代碼可以看到詳細錯誤)
pod lib lint
pod lib lint --verbose --no-clean
如果你看到passed invalidation的話,就說明你大功告成了。
如果你出了這個問題:
Encountered an unknown error (/usr/bin/xcrun simctl list -j devices)
說明沒有將Command Line Tools工具放到xcode中,詳見https://stackoverflow.com/questions/29108172/xcrun-unable-to-find-simctl
2.3.3 提交修改文件到github上
1,pod驗證
set the new version to 1.0.0
set the new tag to 1.0.0
2,將本地git倉庫更新到遠程的倉庫
git add .
git commit -m "release 1.0.0"
git tag '1.0.0'
git push --tags
git push origin master
這里我還遇到一個錯誤,git倉庫指向錯誤的倉庫,這個google上有解答的,用git remote --v查看,然后git set_url,具體可以google一下。
2.4將podspec文件跟新到CocoaPods官方倉庫
最后一步啦,小伙伴們,堅持一下。
2014年之前是需要向pod官方發pull request的,現在不要啦,我看的博客是2014之前的,所以得到的回復是
下面我會貼出來2014年之前的,大家可以了解一下過程,現在只需要幾行代碼就可以啦。下面是代碼和成功的界面。
pod trunk push LLToast.podspec
如果大家遇到下面這個問題
Encountered an unknown error (/usr/bin/xcrun simctl list -j devices)
原因可能有很多種,我的原因是是xcode沒有配置上Command Line Tools,詳見https://stackoverflow.com/questions/29108172/xcrun-unable-to-find-simctl。
附:2014年如何更新pod到官方倉庫
2.4.1 fork官方倉庫并clone下來
fork一份CocoaPods官方的Specs倉庫:傳送門。
然后clone下來
https://github.com/lilianmao/Specs
2.4.2 將自己的podspec文件夾放到spec并更新遠程倉庫
然后更新遠程倉庫
git add.
git commit -m "add Toast spec"
git push origin master
2.4.3 向官方發送pull request,等待通知。
3參考文章
https://guides.cocoapods.org/
http://blog.csdn.net/wzzvictory/article/details/20067595
http://www.lxweimin.com/p/89605e02bf18