Cocoapods常用代码综合:
最新版的Cocoapods安装请移步:http://www.jianshu.com/p/9e4e36ba8574
验证ruby镜像:
<span style="font-size:14px;">$ gem sources -l
$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ sudo gem install cocoapods
$ pod search AFNetworking
platform :ios, ‘7.0’ </span>
发布报错:
<span style="font-size:14px;">Error ITMS-90635 - Invalid Mach-O in bundle - submitting to App store</span>
因为CocoPods导入的框架bitCode不一致导致的,解决方案是在Podfile后面加上
<span style="font-size:14px;">post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end</span>
然后 :
$ pod install --no-repo-update(pod install --verbose --no-repo-update)
如果 pod install报错,报错如下:
[!] Invalid `Podfile` file: syntax error, unexpected tCONSTANT, expecting end-of-input
...ig.build_settings['OTHER_CFLAGS'] || ['$(inherited)']
... ^. Updating CocoaPods might fix the issue.
那就需要先删除之前Podfile里面加的post_install do |installer|...... ,然后pod update,在update之前记得给第三方框架指定一个版本(某些框架最新的可能在你项目无法使用,出现bug),升级后再次执行上面的步骤
另:
删除本地缓存
<span style="font-size:14px;">$ sudo rm -fr ~/.cocoapods/repos/master</span>
如果误将cocoapods升级到1.0.2或者之后的,则可以先卸载cocoapods:
<span style="font-size:14px;">$ sudo gem uninstall cocoapods</span>
然后安装制定版本:
<span style="font-size:14px;">$ sudo gem install cocoapods -v 0.39.0</span>
查看cocoapods版本号:
<span style="font-size:14px;">$ pod --version</span>
升级cocoapods到最新版本
<span style="font-size:14px;">$ sudo gem install -n /usr/local/bin cocoapods</span>
关于Podfile文件编辑时,第三方库版本号的各种写法:
pod ‘AFNetworking’ //不显式指定依赖库版本,表示每次都获取最新版本
pod ‘AFNetworking’, ‘2.0’ //只使用2.0版本
pod ‘AFNetworking’, ‘>2.0′ //使用高于2.0的版本
pod ‘AFNetworking’, ‘>=2.0′ //使用大于或等于2.0的版本
pod ‘AFNetworking’, ‘<2.0′ //使用小于2.0的版本
pod ‘AFNetworking’, ‘<=2.0′ //使用小于或等于2.0的版本
pod ‘AFNetworking’, ‘~>0.1.2′ //使用大于等于0.1.2但小于0.2的版本,相当于>=0.1.2并且<0.2.0
pod ‘AFNetworking’, ‘~>0.1′ //使用大于等于0.1但小于1.0的版本
pod ‘AFNetworking’, ‘~>0′ //高于0的版本,写这个限制和什么都不写是一个效果,都表示使用最新版本
如果报错“[!] The dependency `SDWebImage` is not used in any concrete target.”,这就可能是你创建项目时候勾选有多个target,
如下图所示:
这时候就需要在podfile中明确你要添加到那个target里边,具体代码为:
target'项目包名'
如下图所示:
然后再pod install就可以了