深圳app客户端做网站,微网站 开发,详细描述如何进行搜索引擎的优化,北大企业管理培训课程####导语#xff1a; 有时候看到其他人 source开源时候用pod xxx 配置在你的Podfile文件中#xff0c;执行下pod install 或者 pod update #xff0c;代码瞬间就到你的pod库, 顿时觉得高大上。那是怎么做到的呢#xff1f; Agenda: CocoaPods 的由来Github 使用PodSpec介绍…####导语 有时候看到其他人 source开源时候用pod xxx 配置在你的Podfile文件中执行下pod install 或者 pod update 代码瞬间就到你的pod库, 顿时觉得高大上。那是怎么做到的呢 Agenda: CocoaPods 的由来Github 使用PodSpec介绍PodSpec上传遇到的坑及解决方案###一,CocoaPods 的由来 Android app目前通过gradle来管理和配置你的source,比如需要用到Eventbus只要在build.gradle中配置下 dependencies {compile org.greenrobot:eventbus:3.0.0
}
复制代码iOS必须要有类似的神器啊CocoaPod就是这把神器. 在CocoaPod没出来之前iOS要用引用第三库的做法如下 比如引用AFNetWorking库需要去下载源码然后需要配置对应的编译环境等。当AFNetWorking库升级所有过程又来一遍。过程太过复杂啦。 CocoaPods因上面的原因应运而生它目前是iOS最有名的类库管理工具了通过cocoaPods只需要一行命令就可以完全解决当然前提是你必须正确设置它。目前绝大部分有名的开源类库都支持CocoaPods。所以作为iOS程序员的我们掌握CocoaPods的使用是必不可少的基本技能了。 如果你mac上没有安装pod sudo gem install cocoapods 具体怎么安装可以参考如下链接 http://www.jianshu.com/p/9e4e36ba8574 开发iOS应用用到pod 的主要命令如下 pod help--查看pod命令的帮助
pod search -- Search for pods搜索pod
pod trunk -- Interact with the CocoaPods API (e.g. publishing new specs) 上传source到trunk
pod spec -- Manage pod specs//管理pod spec
pod install --Install project dependencies according to versions from a Podfile.lock //安装项目中的依赖项目
pod update --Update outdated project dependencies and create new Podfile.lock//跟新依赖项目并且更新Podfile.lock
pod init --Generate a Podfile for the current directory//创建pod file文件
复制代码其中Podfile.lock的扮演的角色非常重要具体作用可以参考如下链接 http://m.blog.csdn.net/muzhenhua/article/details/45174071 ####二Github 使用 为嘛要介绍GitHub呢CocoaPods只是做为项目的具体管理者podspec文件就放在cocoapod官网上供大家搜索。但是实际源码则是存储在Github上那怎么使用Github就非常关键啦。 创建项目 登录你的Github,然后去创建一个新的仓库如下图创建GKFramework参考 上传项目 下载该仓库通过git clone 。clone一个仓库下来 怎么clone如下图clone with https. 在终端输入 //git clone后面的是你对应的git 地址
git clone https://github.com/wongstar/GKFramework.git复制代码然后在这个仓库中修改或者添加你需要对应类或者文件等。 然后通过下面命令 //add 所有的到仓库
git add *
//提交commit信息
git commit
//提交本地到远端
git push origin master
复制代码打tag tag是后续spec中需要用到以后升级至需要升级对应tag.//获取当前有多少tag
git tag
//创建tag 0.0.1版本
git tag 0.0.1
复制代码update tag到Github上 上传tag到Github服务器上这个比较简单 git push origin 0.0.1
复制代码查看tag 如下图所示 点击branch 然后查看Tags栏目 至此源码已经上传到Github服务器上去了但是Pod服务器上目前还没有对应的描述下面接着介绍PodSpec,以及如何上传到cocoapod服务器上去. ####三,PodSpec介绍 在mac 上创建一个podspec,在Terminal终端上输入下面命令 //注GKFramework.podspec是你的框架名称
pod spec create GKFramework.podspec
复制代码然后编辑podspec文件。如下GKFramework.podspec Pod::Spec.new do |s|s.name GKFramework //定义名称s.version 0.0.5 //tag版本s.summary A Sample.so you can use it //简介,以后search到简介s.description -DESCthis is gk framework, use it for test your framework. we can use it as framework.DESC
//s.description 定义具体的描述s.homepage https://github.com/wongstar/GKFrameworks.license { :type MIT, :file LICENSE }//具体licenses.author { wongstar wongstar.iacgmail.com }s.platform :ios, 8.0//build的平台s.ios.deployment_target 7.0//最低开发s.source { :git https://github.com/wongstar/GKFramework.git, :tag #{s.version} }s.source_files Classes/**/*#s.public_header_filesGKFramework/Classes/**/*.hend复制代码 s.description -DESCthis is gk framework, use it for test your framework. we can use it as framework.DESC
s.description定义了描述该pod是用来做什么的。注意这里的写法复制代码s.description格式要求必须是下面的这样描述 -DESC 这里面你定义的描述.必须用这个格式 DESC s.source { :git https://github.com/wongstar/GKFramework.git, :tag #{s.version} }
复制代码必须定义s.sourcegit链接必须是你上传过的source, tag定义为你在github上对source打的tag. s.source_files Classes/**/* 定义为Classes目录下的所有文件
复制代码s.dependency依赖库不能依赖未发布的库
eg: s.dependency AFNetworking
复制代码####四,PodSpec上传 在 cocoapods 注册//email代表你的emailusername代表你的用户名pod trunk register email username
复制代码执行完上面的命令你的邮箱会收到一封确认信点击确认验证一下就ok啦。 判断podspec正确行//GKFramework.podspec为你对应的podspec文件
pod spec lint GKFramework.podspec
复制代码如果是正确的spec会出现下面的提示 上传到cocoapod服务器//注GKFramework.podspec为你对应spec的名称
pod trunk push GKFramework.podspec
复制代码上传成功如下图所示 search 你的库. 网址为https://cocoapods.org/ 如图五search GKFramework ####五,遇到的坑及解决方案source file没找到 [iOS] file patterns: The source_files pattern did not match any file. 确保你的source file是否配置正确如你的spec目录和source对应的关系cocoapods环境问题 unknown: Encountered an unknown error (Simulator iPhone 4s is not available.) during validation 执行下面命令sudo gem install cocoapods --pre
复制代码如果执行上面的有问题出现 ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/xcodeproj 执行下面命令 sudo gem install -n /usr/local/bin cocoapods
复制代码Swift 版本问题 [!] 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.
复制代码验证失败会出现一系列错误但也不是无根可寻其中出现错误频率最多的提示是 source files没找到 ERROR | [iOS] file patterns: The source_files pattern did not match any file.此错误的原因是没有找到匹配的文件。 解决方案 手动创建文件具体操作方法如下 终端输入 open /Users/icepoint/Library/Caches/CocoaPods/Pods/External/GKFramework/035cb9aa62b9d49f904fad1119b83da4-aebfe 进入相应文件夹创建文件夹与source_files文件路径对应 GKFramework/GKFramework/Classes 文件结构如下 GKFramework └── 035cb9aa62b9d49f904fad1119b83da4-aebfe ├── GKFramework │ └── GKFramework │ └──Classes └── LICENSE #开源协议 默认MIT Classes文件夹存放自己的库文件 pod search GKFramework 搜索不到 Unable to find a pod with name, author, summary, or description matching GKFramework. 解决办法 1.pod install --repo-update 2.或者全部删除:使用命令:rm ~/Library/Caches/CocoaPods/search_index.json 重新search GKFramework