标签:
摘要:
CocoaPods是提供对第三方库依赖的管理工具,通过CocoaPods我们可以方便的管理每一个第三方库:添加、删除和更新,不需要我们做太多的配置工作,如此便可直观、集中和自动化地管理我们项目的第三方库。
本文不对CocoaPods做全面的介绍,想对CocoaPods做更多了解的可以阅读这篇文章:Cocoapods完整使用篇。本文主要介绍一下如何给自己的开源项目添加CocoaPods的支持。
一、创建一个配置文件(pod spec create 文件名)
要使得我们的项目支持CocoaPods,就需要告诉CocoaPods我们的项目的一些信息:源文件地址、支持的平台和版本、编译条件、依赖的系统库及第三方的库等等。这些信息是通过一个以“spec”为扩展名的文件存储起来的。因此,我们需要创建这个配置文件,编辑好项目的配置信息,然后把这个文件上传给CocoaPods。
pod spec create YQXxxxxxx
二、编辑配置文件(配置项目的信息)
1 # 2 # Be sure to run `pod spec lint YQTest.podspec‘ to ensure this is a 3 # valid spec and to remove all comments including this before submitting the spec. 4 # 5 # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 # 8 9 Pod::Spec.new do |s| 10 11 # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 # 13 # These will help people to find your library, and whilst it 14 # can feel like a chore to fill in it‘s definitely to your advantage. The 15 # summary should be tweet-length, and the description more in depth. 16 # 17 18 s.name = "YQTest" #项目名称 19 s.version = "0.0.1" #项目版本 20 s.summary = "A short description of YQTest." #项目摘要 21 22 # This description is used to generate tags and improve search results. 23 # * Think: What does it do? Why did you write it? What is the focus? 24 # * Try to keep it short, snappy and to the point. 25 # * Write the description between the DESC delimiters below. 26 # * Finally, don‘t worry about the indent, CocoaPods strips it! 27 28 s.homepage = "http://EXAMPLE/YQTest" 29 # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 30 31 32 # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 33 # 34 # Licensing your code is important. See http://choosealicense.com for more info. 35 # CocoaPods will detect a license file if there is a named LICENSE* 36 # Popular ones are ‘MIT‘, ‘BSD‘ and ‘Apache License, Version 2.0‘. 37 # 38 39 s.license = "MIT" 40 # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 41 42 43 # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 44 # 45 # Specify the authors of the library, with email addresses. Email addresses 46 # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 47 # accepts just a name if you‘d rather not provide an email address. 48 # 49 # Specify a social_media_url where others can refer to, for example a twitter 50 # profile URL. 51 # 52 53 s.author = { "yanghy" => "yanghy2013@gmail.com" } 54 # Or just: s.author = "yanghy" 55 # s.authors = { "yanghy" => "yanghy2013@gmail.com" } 56 # s.social_media_url = "http://twitter.com/yanghy" 57 58 # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 59 # 60 # If this Pod runs only on iOS or OS X, then specify the platform and 61 # the deployment target. You can optionally include the target after the platform. 62 # 63 64 #项目支持的平台及系统版本,若只支持ios,删除注释符号 65 # s.platform = :ios 66 # s.platform = :ios, "5.0" 67 68 # When using multiple platforms 69 # s.ios.deployment_target = "5.0" 70 # s.osx.deployment_target = "10.7" 71 # s.watchos.deployment_target = "2.0" 72 # s.tvos.deployment_target = "9.0" 73 74 75 # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 76 # 77 # Specify the location from where the source should be retrieved. 78 # Supports git, hg, bzr, svn and HTTP. 79 # 80 81 s.source = { :git => "http://EXAMPLE/YQTest.git", :tag => 0.0.1" } 82 83 84 # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 85 # 86 # CocoaPods is smart about how it includes source code. For source files 87 # giving a folder will include any swift, h, m, mm, c & cpp files. 88 # For header files it will include any header in the folder. 89 # Not including the public_header_files will make all headers public. 90 # 91 92 s.source_files = "Classes", "Classes/**/*.{h,m}" #源文件 93 #s.exclude_files = "Classes/Exclude" 94 95 # s.public_header_files = "Classes/**/*.h" 96 97 98 # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 99 # 100 # A list of resources included with the Pod. These are copied into the 101 # target bundle with a build phase script. Anything else will be cleaned. 102 # You can preserve files from being cleaned, please don‘t preserve 103 # non-essential files like tests, examples and documentation. 104 # 105 106 # s.resource = "icon.png" 107 # s.resources = "Resources/*.png" 108 109 # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 110 111 112 # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 113 # 114 # Link your library with frameworks, or libraries. Libraries do not include 115 # the lib prefix of their name. 116 # 117 118 #依赖的系统框架 119 # s.framework = "SomeFramework" 120 # s.frameworks = "SomeFramework", "AnotherFramework" 121 122 #第三方依赖 123 s.dependency "Masonry", "~>0.6" 124 125 # s.library = "iconv" 126 # s.libraries = "iconv", "xml2" 127 128 129 # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 130 # 131 # If your library depends on compiler flags you can set them in the xcconfig hash 132 # where they will only apply to your library. If you depend on other Podspecs 133 # you can include multiple dependencies to ensure it works. 134 135 # 是否支持arc 136 s.requires_arc = true 137 138 # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 139 # s.dependency "JSONKit", "~> 1.4" 140 141 end
三、配置代码仓库
因为在第二步的配置文件中给版本号配置了:0.0.1,因此我们须要给我们的项目配置一个tag,使用如下命令
1 git tag 0.0.1 #添加一个tag 2 git push --tags #推送tag到远程
四、验证我们的配置是否正确
1 pod spec lint YQXxxx.podspec
我在配置过程中出现吃错误:
1、因为项目中使用了UIKit,但是在配置中没有指定平台,因此在OSX平台上编译错误
解决办法:指定项目的平台 (# s.platform = :ios)
2、没有指定系统的版本号,在不支持arc的系统下编译失败
解决办法:指定系统版本(# s.platform = :ios, "5.0")
五、提交到CocoaPods
1 pod trunk push YQXxxx.podspec
没有配置作者的会出现:[!] You need to register a session first.错误,此时用如下命令注册一个会话后再提交
1 pod trunk register email "name" --description="macbook pro"
到此为止,你就可以使用pod search 搜索到你的项目了!
标签:
原文地址:http://www.cnblogs.com/yueyuanyueyuan/p/5560954.html