简单介绍
想必有很多人和我一样,在刚接触开发时,喜欢使用一些第三方的工具。
慢慢的也会想着能否把自己的日常积累,分享到GitHub中。也能和调用第三方工具一样,简单方便的引用自己的在GitHub上的工具。
那么问题来了,BD了很多资料,到底有没有学废呢?
今天,手把手带你实操,包教包废。
准备材料
1、自己的GitHub账号。注册地址:https://github.com。进入后点击==sign up==进行注册。具体需要填写资料,自行解决。
2、能够独立使用的DEMO,保证自己的代码,导入到任何项目都能使用。尽量避免依赖。例如:构建视图工具时,你的适配是否使用了==masonry==的第三方库。
3、桌面创建GitHub文件夹,方便后面使用。并将自己要上传的文件夹,放入此文件夹中。如图:
4、mac需要安装pod(bd可查到很多方法)
开始制作
一、上传文件到github
1、此过程忽略,自行上传文件,获取到github文件地址就行。
2、上传的github的文件,需要打tag。
二、创建spec文件
1、cd到前面我们创建的文件目录下
cd /Users/wangyazhen/Desktop/GitHub
2、创建spec,name可以写自己需要的名称
pod spec create name
此时生成spec如图:
3、已生成的spec文件,内容一堆。我们删繁就简
删除前:
#
# Be sure to run `pod spec lint name.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 https://guides.cocoapods.org/syntax/podspec.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |spec|
# ――― 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.
#
spec.name = "name"
spec.version = "0.0.1"
spec.summary = "A short description of name."
# 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!
spec.description = <<-DESC
DESC
spec.homepage = "http://EXAMPLE/name"
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See https://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'.
#
spec.license = "MIT (example)"
# spec.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.
#
spec.author = { "艾苏安" => "2024506004@qq.com" }
# Or just: spec.author = "艾苏安"
# spec.authors = { "艾苏安" => "2024506004@qq.com" }
# spec.social_media_url = "https://twitter.com/艾苏安"
# ――― 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.
#
# spec.platform = :iOS
# spec.platform = :ios, "5.0"
# When using multiple platforms
# spec.ios.deployment_target = "5.0"
# spec.osx.deployment_target = "10.7"
# spec.watchos.deployment_target = "2.0"
# spec.tvos.deployment_target = "9.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
spec.source = { :git => "http://EXAMPLE/name.git", :tag => "#{spec.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.
#
spec.source_files = "Classes", "Classes/**/*.{h,m}"
spec.exclude_files = "Classes/Exclude"
# spec.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.
#
# spec.resource = "icon.png"
# spec.resources = "Resources/*.png"
# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
# spec.framework = "SomeFramework"
# spec.frameworks = "SomeFramework", "AnotherFramework"
# spec.library = "iconv"
# spec.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.
# spec.requires_arc = true
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# spec.dependency "JSONKit", "~> 1.4"
end
删除后:
Pod::Spec.new do |spec|
spec.name = "name"
spec.version = "0.0.1"
spec.summary = "A short description of name."
spec.description = <<-DESC
DESC
spec.homepage = "http://EXAMPLE/name"
spec.license = "MIT (example)"
spec.author = { "DEMOKING" => "2024506004@qq.com" }
spec.platform = :iOS
spec.platform = :ios, "5.0"
spec.source = { :git => "http://EXAMPLE/name.git", :tag => "#{spec.version}" }
spec.source_files = "Classes", "Classes/**/*.{h,m}"
spec.exclude_files = "Classes/Exclude"
end
修改对应文件:核心
Pod::Spec.new do |spec|
spec.name = "DKKit"
spec.version = "0.0.1"
spec.summary = "dkkit for oc"
spec.description = "dkkit for oc tool"
spec.homepage = "https://github.com/DEMOKING"
spec.license = "MIT"
spec.author = { "DEMOKING" => "2024506004@qq.com" }
spec.platform = :iOS
spec.platform = :ios, "8.0"
spec.source = { :git => "https://github.com/DEMOKING/dkkit.git", :tag => "0.0.1" }
spec.source_files = "DEMOKING/Category/*.{h,m}","DEMOKING/Tool/*.{h,m}"
end
三、检查space文件
1、在含有space文件的目录下执行。这个过程会有很多意想不到,或者看着不明白的错误。大都和space文件有关。对比上面修改前后的space文件去试错。
pod lib lint --verbose --no-clean --allow-warnings
2、执行结果
name passed validation.
四、第一次上传spec文件
1、此过程需要登录和认证。
2、已认证的后续可以直接上传。
注册
1、使用邮箱注册
pod trunk register xxxxxxxx@xx.com
2、执行结果,打开邮箱认证。此时点击邮箱链接会自动跳转到终端。
[!] Please verify the session by clicking the link in the verification email that has been sent to 2024506004@qq.com
上传
1、上传spec文件
pod trunk push /Users/wangyazhen/Desktop/GitHub/name.podspec
2、上传完成
--------------------------------------------------------------------------------
🎉 Congrats
🚀 name (0.0.1) successfully published
📅 April 26th, 22:33
🌎 https://cocoapods.org/pods/name
👍 Tell your friends!
--------------------------------------------------------------------------------
3、一般10-30分钟后,可在github上搜到自己的杰作
注意事项
1、本案例为比较简单版本的上传cocoapods的方法;
2、自己使用时,期间避免不了多多少少出现问题;
3、多查阅资料,避免误导;
4、如有问题,留言及时回复;