• 组件化开发-002-Cocoapods远程私有库使用(Private Repo)


    创建一个私有的podspec包括如下那么几个步骤

    1. 创建并设置一个私有的Spec Repo。
    2. 创建Pod所需要的项目工程文件,并且有可访问的项目版本控制地址。
    3. 创建Pod所对应的podspec文件。
    4. 本地测试配置好的podspec文件是否可用。
    5. 向私有的Spec Repo中提交podspec。
    6. 在个人项目中的Podfile中增加抽取好的Pod并使用。
    7. 更新podspec。

    本地私有仓库

    什么是Spec Repo?他是所有的Pods的一个索引,就是一个容器,所有公开的Pods都在这个里面,他实际是一个Git仓库,remote端在GitHub上,当我们使用Cocoapods后它会被clone到本地的~/.cocoapods/repos目录下,可以进入到这个目录看到master文件夹就是这个官方的Spec Repo了。这个master目录的结构是这个样子的。

     

    1.在码云上创建一个私有库

    https://gitee.com/Steven_Hu/HKCommonTools.git

    2.将私有库添加到本地

    pod repo add  REPO_NAME  SOURCE_URL

    $pod repo add CommomToolSpec https://gitee.com/Steven_Hu/HKCommonTools.git

    Cloning spec repo `CommomToolSpec` from `https://gitee.com/Steven_Hu/HKCommonTools.git`

    3.cd 到桌面开始组件化抽取

    cd ./Desktop

    pod lib create HKCommonTool

    Cloning `https://github.com/CocoaPods/pod-template.git` into `HKCommonTool`.
    Configuring HKCommonTool template.
    ! Before you can create a new library we need to setup your git credentials.
     What is your email?
     > 916109796@qq.com
    ! Setting your email in git to 916109796@qq.com
      git config user.email "916109796@qq.com"
    ------------------------------
    To get you started we need to ask a few questions, this should only take a minute.
    If this is your first time we recommend running through with the guide: 
     - https://guides.cocoapods.org/making/using-pod-lib-create.html
     ( hold cmd and double click links to open in a browser. )
    
    What platform do you want to use?? [ iOS / macOS ]
     > iOS
    What language do you want to use?? [ Swift / ObjC ]
     > ObjC
    Would you like to include a demo application with your library? [ Yes / No ]
     > Yes
    Which testing frameworks will you use? [ Specta / Kiwi / None ]
     > None
    Would you like to do view based testing? [ Yes / No ]
     > Yes
    What is your class prefix?
     > HK
    Running pod install on your new library.
    Pod installation complete! There are 2 dependencies from the Podfile and 1 total pods installed.

    把要抽取的工具类拖到 Pods ->Development Pods 下的Replace.m 中并替换掉它。

    cd 到工程目录下 执行 pod install

    4.推送到远程私有库(git远程仓库地址,或者码云等)

    //关联远程仓库

    在 HKCommonTool 工程目录下 执行:

    $git remote add origin https://gitee.com/Steven_Hu/HKCommonTools.git

    //提交到git仓库

    git add .
    git commit -m 'HKCommonTool初始化'
    git push origin master
    git push origin master -f //全局提交

    5.修改 .podspec 文件并提交

    Pod::Spec.new do |s|
      #名称
      s.name             = 'HKCommonTool'
      #版本号
      s.version          = '0.1.0'
      #摘要
      s.summary          = 'HKCommonTool 常用工具类归类'
      #描述
      s.description      = 'iOS开发常用的常用宏定义和工具类,网络框架等~'
      #远程仓库首页链接
      s.homepage         = 'https://gitee.com/Steven_Hu/HKCommonTools'
      #截图
      # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
      #许可证
      s.license          = { :type => 'MIT', :file => 'LICENSE' }
      #作者
      s.author           = { 'HJT916109796' => '916109796@qq.com' }
      #source来源
      s.source           = { :git => 'https://gitee.com/Steven_Hu/HKCommonTools.git', :tag => s.version.to_s }
      #社交链接
      # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
      #开发版本
      s.ios.deployment_target = '9.0'
      #资源文件路径
      s.source_files = 'HKCommonTool/Classes/**/*'
      #资源包
      # s.resource_bundles = {
      #   'HKCommonTool' => ['HKCommonTool/Assets/*.png']
      # }
      # s.public_header_files = 'Pod/Classes/**/*.h'
      # s.frameworks = 'UIKit', 'MapKit'
      # s.dependency 'AFNetworking', '~> 2.3'
    end

    校验文件的正确性

    $pod lib lint HKCommonTool.podspec
    //去掉警告
    $pod lib lint --allow-warnings

    重新提交:

    git add .
    git commit -m '修改podspec文件~'
    git push origin master

    设置tag

    git tag
    git tag '0.1.0'
    git push --tags

    6.推送本地Spec到远程仓库

    git fetch origin master

    git checkout master

    git branch --set-upstream-to=origin/master master

    Branch 'master' set up to track remote branch 'master' from 'origin'.

    git pull

    pod repo update

    pod repo push CommomToolSpec HKCommonTool.podspec 

    git push 

    git pull

    git push origin master

    7.如何使用:

    编辑Podfile文件如下

    编辑Podfile 必须加  git => 'https://gitee.com/Steven_Hu/HKCommonTools.git'

     

    platform :ios, '9.0'
    use_frameworks!
    
    target 'HKTools' do
      
      pod 'XCDemo'  ,:git => 'https://gitee.com/Steven_Hu/XCTool.git'
      pod 'HKCommonTool'  ,:git => 'https://gitee.com/Steven_Hu/HKCommonTools.git'
    #  pod 'HKTools', :path => './Lib/HKTools'
    #  pod 'HKTools', :podspec => '~/.cocoapods/repos/HKTools/HKTools.podspec'
    end

    8.需要添加依赖的组件化抽取

    use_frameworks!
    platform :ios, '8.0'
    target 'XBTool_Example' do
        
      pod 'XBTool', :path => '../'
      pod 'AFNetworking', '~> 3.1.0'
    end

    此时找不到AFN,解决办法 将use_frameworks!删除 使用:(dynamic framework) 不使用:(static libraries)

    #use_frameworks!  ---- dynamic framework
    #不使用!  ---- static libraries方式
    platform :ios, '8.0'
    target 'XBTool_Example' do
        
      pod 'XBTool', :path => '../'
      pod 'AFNetworking', '~> 3.1.0'
    end

    9.组件化通讯原理(路由Route)

    1.URL

    2.Runtime+命令模式(Target-Action)。

    解耦(不import,发送命令时,不需要知道请求的接收者是谁,提供TARGET分发命令)

    角色划分:

    Command :抽象命令类-提供接口

    ConcreteCommand : 具体命令类—具体命令

    Invoker:调用者

    Receiver : 接收者

    Client:客户类

    10.其他常用命令:

    //1.cd /Users/MengYu/Desktop/HKTools
    pod init
    //2.cd /Users/MengYu/Desktop/HKTools/Lib/
    pod lib create HKTools
    iOS, ObjC, Yes,None,No,HK
    //3.抽取替换Replace.m
    添加依赖,pod install
    //4.提交码云:
    cd /Users/MengYu/Desktop/HKTools/Lib/HKTools/
    git remote add origin https://gitee.com/Steven_Hu/HKTools.git
    git add .
    git commit -m 'HKTools初始化'
    git push origin master -f
    //5.校验本地podspec文件是否可用
    pod lib lint 
    $pod lib lint HKCommonTool.podspec
    //去掉警告
    $pod lib lint --allow-warnings
    //查看报错详细信息
    pod lib lint --verbose
    //6.设置tag
    git tag
    git tag '0.1.0'
    git push --tags
    //7.设置推送到主干
    git fetch origin master
    git checkout master
    git branch --set-upstream-to=origin/master master
    //8.删除本地私有库
    pod repo remove 私有库名字
    //9.删除源
    git remote remove origin
    //10.克隆
    git clone 仓库地址
    //11.更新 速度快
    pod install --verbose --no-repo-update

     12.组件化抽取第二个

    cd 到lib文件夹路径

    pod lib create 工具类名

     CocoaPods .podspec文件配置详解

    # 开放的库文件 * 表示通配
    s.source_files = 'HKWebView/Classes/**/*'
    #  *.{png,js,html} 表示查询png 和 js 和 html 后缀名的文件
    s.resource_bundles = {
    'HKWebView' => ['HKWebView/Assets/*.{png,js,html}']
    }
  • 相关阅读:
    团队项目前期冲刺-5
    团队项目前期冲刺-4
    团队项目前期冲刺-3
    团队项目前期冲刺-2
    团队计划会议
    团队项目前期冲刺-1
    大道至简阅读笔记01
    软件工程第八周总结
    梦断代码阅读笔记03
    小组团队项目的NABCD分析
  • 原文地址:https://www.cnblogs.com/StevenHuSir/p/ComponentBased_PrivateRepo.html
Copyright © 2020-2023  润新知