CocoaPods 创建私有库管理包

来源:互联网 发布:涂师傅数据恢复能用吗 编辑:程序博客网 时间:2024/04/29 08:34


参考:私有库创建 : http://www.cocoachina.com/ios/20150930/13471.html


       1、pod lib create LSLog 创建需要打包成库的项目

     此过程会问5个问题:

           

    然后生成如图工作空间目录:

         

    MyLog下的MyLog 是存放地址源文件的,里面有Asset ,Classes两个文件夹。分别存放图片和源码文件。

    2、cd LSLog 目录下,添加远程仓库。          

          git remote add origin http://192.168.2.250:8080/scm/git/MyLog

    编辑LSLog.podspec 文件。 格式如下:

           

    Pod::Spec.new do |s|

      s.name             = "MyLog"

      s.version          = "0.1.0"

      s.summary          = " MyLog Log what you input."




      s.description      = <<-DESC

    TODO: Add long description of the pod here.

                           DESC


      s.homepage         = "http://192.168.2.250:8080/scm/git/MyLog"


      s.license          = 'MIT'

      s.author           = { "luosai" => "luosai19910103@163.com" }

      s.source           = { :git => "http://192.168.2.250:8080/scm/git/MyLog", :tag => s.version.to_s }



      s.ios.deployment_target = '8.0'


      s.source_files = 'MyLog/Classes/**/*'

      

      s.resource_bundles = {

        'MyLog' => ['MyLog/Assets/*.png']

      }

      s.public_header_files = 'MyLog/Classes/**/*.h'

    end


    4、将需要用pod管理的文件放到MyLog 下 ,该目录
          s.source_files = 'MyLog/Classes/**/*' 告知pod 管理的源文件位置。
       这里在Classes 放入两个文件 MyLog.h MyLog.m , MyLog.m 源码为:
       

    #import "MyLog.h"


    @implementation MyLog

    +(void)Log:(NSString *)str{

      NSLog(@"恭喜你成功了!!%@",str);

    }

    @end

    5、pod lib lint   检查是否可用


    6、提交项目到远程仓库。

            git add .

    git commit -m’init'

    git push origin master  推送到远程仓库

    git tag 0.1.0  打tag .

    git push —tags 将tag推送到远程仓库

    7、创建本地pod repo 仓库(Mylog)并添加远程仓库

            pod repo add Mylog 'http://luosai@192.168.2.250:8080/scm/git/MyLogSpec' 

     此过程会在~/.cocoaPod/repos/ 下创建一个本地 MyLog 仓库 


    8 、将本地MyLog.podspec 添加到本地  pod repo 仓库并推送到远程仓库

    pod repo push Mylog MyLog.podspec  .

    9、 创建新项目进行测试

          cd 到 项目根目录:pod init 

         vi Podfile 

         

    source 'http://luosai@192.168.2.250:8080/scm/git/MyLogSpec'

    target 'TestMyLog'do

        pod 'MyLog','~>0.1.0'

    end


    target 'TestMyLogTests'do


    end


    target 'TestMyLogUITests'do


    end


    添加头文件 并使用

    #import "MyLog.h"

        

    #import "ViewController.h"

    #import "MyLog.h"

    @interface ViewController ()


    @end


    @implementation ViewController


    - (void)viewDidLoad {

        [superviewDidLoad];

        [MyLogLog:@"中奖一百万"];

    }


    @end


    运行项目:打印结果

      2016-05-09 10:06:50.536 TestMyLog[1779:43808] 恭喜你成功了!!中奖一百万

       

    大功告成。

        





0 0
原创粉丝点击