• XCode发布代码到Cocoapod


    发布代码到Cocoapod

    @(iOS)[CocoaPods]

    • 有些公共类,想要放到Cocoapod,这样以后维护起来比较方便。
    • 或者自己封装的一些便捷控件都可以发布到Cocoapod。

    新建一个工程

    • 把需要的封装好的类放到工程中

    • 添加demo应用
      Alt text
      Alt text

    • 写个小demo,调用一下试试

    提交到github

    • 拿到github链接
    • 这是为了Cocoapod能找到源文件

    增加CaptureImagePro.podspec

    • 这个文件是给Cocoapod进行索引用的

    • 1、添加tag git tag -a 1.0.0 -m "tag 1.0.0

    • 2、push git push --tags

    • 3、创建podspec文件 pod spec create CaptureImagePro

    • 4、修改podspec

    Pod::Spec.new do |s|
    s.name         = 'CaptureImagePro'
    s.version      = '1.0.0'
    s.license      = { :type => 'MIT', :file => 'LICENSE' }
    s.homepage     = 'https://github.com/slq0378'
    s.authors      = {'MrSong' => 'slq0378@163.com'}
    s.summary      = '通过AVFoundation自定义相机,可有效降低内存占用'
    
    s.platform     =  :ios, '7.0'
    s.source       =  {:git => 'https://github.com/slq0378/CaptureImagePro.git', :tag => s.version}
    s.source_files = 'CaptureImagePro/SLQCameraViewController'
    s.frameworks   =  'AVFoundation'
    s.requires_arc = true
    
    end
    
    • 5、验证spec文件有效性 pod spec lint CaptureImagePro.podspec
      • 如果有警告,直接--allow-warnings忽略
    song$ pod spec lint CaptureImagePro.podspec 
    
     -> CaptureImagePro (1.0.0)
        - WARN  | xcodebuild:  CaptureImagePro/CaptureImagePro/SLQCameraViewController/SLQCameraHelper.m:346:12: warning: incompatible pointer types returning 'CIImage *' from a function with result type 'UIImage *' [-Wincompatible-pointer-types]
    
    Analyzed 1 podspec.
    
    [!] The spec did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
    

    trunk 到Cocoapod

    • 使用pod trunk命令上传项目至Cocoapods

    • 参考Cocoapod官网

    • 1、注册 pod trunk register xxxxxx@gmail.com 'MrSong' --description='MrSong'

    • 2、邮箱里确认就可上传了 pod trunk push CaptureImagePro.podspec

    • 3、可通过 pod trunk me 查看自己是否成功

    • 4、更新本地库 pod update

    • 5、搜索 pod search 'CaptureImagePro'

      • Alt text

    注意事项

    • 如果自己修复了一个bug,那么要对Cocoapod进行更新操作,过程和上面一样,先tag再trunk。最后自己试一下即可。

    各种坑

    pod spec lint xxx.podsepc 错误

    • ERROR | [iOS] file patterns: The source_files pattern did not match any file.
    • 这次提交代码一直报错,改了很多次才发现问题。问题在于我的目录结构。
    • Alt text
    • 这个工程有个子目录(UIImage),但是我一直是包含一个目录(Categories),这样就找不到子目录
      • 前只包含一个目录 s.source_files = 'SLQCategories/Categories/*.{h,m}' 一直报上面那个错误, 找不到子目录。
      • 后两个目录 s.source_files = 'SLQCategories/Categories/*.{h,m}','SLQCategories/Categories/**/*.{h,m}' 分开来写,分别包含

    pod下来的目录不对

    • 实际需要pod下来的文件目录为了和原先的目录保持一直,我原先以为会和实际目录一直,但是实际情况却相反,所有的文件全部在一个根目录下面。
    • pod 下来是这样

    Alt text

    • podspec文件如下
    Pod::Spec.new do |s|
    s.name         = 'SLQCategories'
    s.version      = '1.0.4'
    s.license      = { :type => 'MIT', :file => 'LICENSE' }
    s.homepage     = 'https://github.com/slq0378'
    s.authors      = {'MrSong' => 'xxxx.com'}
    s.summary      = 'iOS分类集合,各种简单易用分类'
    
    s.platform     =  :ios, '7.0'
    s.source       =  {:git => 'https://github.com/slq0378/SLQCategories.git', :tag => s.version}
    s.source_files =  'SLQCategories/Categories/*.{h,m}','SLQCategories/Categories/UIImage/*.{h,m}'
    s.frameworks   =  'AVFoundation'
    s.requires_arc = true
    
    end
    
    • 实际上我是希望把真是目录显示出来,这样查看比较方便,这里参考AFNetworking的做法。

    • Alt text

    • podspec文件如下

    Pod::Spec.new do |s|
    s.name         = 'SLQCategories'
    s.version      = '1.0.4'
    s.license      = { :type => 'MIT', :file => 'LICENSE' }
    s.homepage     = 'https://github.com/slq0378'
    s.authors      = {'MrSong' => 'xxx@.com'}
    s.summary      = 'iOS分类集合,各种简单易用分类'
    
    s.platform     =  :ios, '7.0'
    s.source       =  {:git => 'https://github.com/slq0378/SLQCategories.git', :tag => s.version}
    s.source_files =  'SLQCategories/Categories/*.{h,m}'
    # s.source_files =  'SLQCategories/Categories/*.{h,m}','SLQCategories/Categories/UIImage/*.{h,m}'
    s.frameworks   =  'AVFoundation'
    s.requires_arc = true
    
    
    # 子目录
    	s.subspec 'UIImage' do |ss|
    	ss.source_files = 'SLQCategories/Categories/UIImage/*.{h,m}'
    	end
    
    end
    

    项目参考
    参考文档1
    参考文档2
    参考文档3

  • 相关阅读:
    upload.go
    heartbeat.go
    delete.go
    get.go
    handler.go
    uuid.go
    kingpin_parser.go
    disk.go
    logrus_hook.go
    反连接NOT EXISTS子查询中有or 谓词连接条件SQL优化一例
  • 原文地址:https://www.cnblogs.com/songliquan/p/12784446.html
Copyright © 2020-2023  润新知