美文网首页
Pod小知识点

Pod小知识点

作者: 春暖花已开 | 来源:发表于2018-10-11 22:56 被阅读11次
    验证

    1、验证.podspec会先测试本地.podspec文件是否存在语法错误。测试成功再根据.podspec文件找到远端仓库对应的版本clone到本地并进行配置。最后测试文件是否能够编译成功。

    2、再次验证
    如果错误发生在.podspec中。当修改完时,不需要再次提交就可以直接验证。如果错误发生在代码中,则需要再次提交才能验证。

    3、pod spec相对于pod lib 会更为精确,pod lib相当于只验证一个本地仓库,pod spec会同时验证本地仓库和远程仓库。

    4、—sources变量的使用
    当你的.podspec文件依赖其他私有库时要引入source
    pod spec lint React.podspec —allow-warnings —sources=lcoal_spec_name,master
    lint通过之后push的时候依然需要—sources
    pod push local_spec_name React.podspec —allow-warning —source=local_spec_name,master


    # s.libraries 表示这个pod依赖的 苹果官方的库,也就是类似libstdc++.a ,libsqlite.a 等等的a文件; 
    # s.vendored_libraries 就表示用户自己的a文件,比如新浪微博SDK的libWeiboSDK.a, 微信libWeChatSDK.a; 
    # s.frameworks 表示pod依赖的 苹果的framework, 比如 UIKit,SystemConfiguration等等 
    # s.vendored_frameworks, 表示pod依赖的自己的framework,比如QQSDK的TencentOpenAPI.framework,JSPatch热更新JSPatchPlatform.framework; 
    # .a 或者 libz.tbd 后缀不要,名字里lib开头的三个字母不要,libz.tbd 应写成 'z'
    

    例如:

    # s.library = 'z' 
    s.libraries = 'iconv','sqlite3','stdc++','z' 
    s.vendored_libraries = 'Resources/lib/**/*.{a}' 
    s.vendored_frameworks = 'Resources/Framework/**/*.{framework}'
    

    依赖版本:
    //使用本地索引库里的最新的版本
    pod 'SSZipArchive' 
    
    //指定使用某个版本
    pod 'SSZipArchive', '2.1.3'
    
    //2.1.3与2.2版本之间的最新版本
    pod 'SSZipArchive', '~> 2.1.3'
    
    //使用大于等于2.1.3的最新版本(可以是2.1.4)
    pod 'SSZipArchive', '>= 2.1.3'
    
    
    Build配置
    //只有在debug模式下才使用PonyDebugger库
      pod 'SSZipArchive', :configuration => 'Debug'
    
    Subspecs 配置
    #Subspecs 配置, 只使用pod中某一个或者某一些子pod 库
    //使用QueryKit下的Attribute库: pod 'QueryKit/Attribute' 
    //使用QueryKit下的Attribute库和QuerySet库: pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
    
    设置pod库
    //使用master分支 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git' 
    //使用指定分支 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :branch => 'dev' 
    //使用指定tag pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0' 
    //使用某一次commit pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af
    
    设置podSpec的来源
    pod 'AFNetworking', :podspec => 'https://example.com/AFNetworking.podspec'
    
    本地pod库(cocoapod会在指定的文件夹下找podspec,所以当前文件夹下一定要有podspec文件)
    pod 'AFNetworking', :path => '~/Documents/AFNetworking'
    
    inherit!:给当前target设置集成模式
    :complete : 全部继承父target 
    :none :全部不继承 
    :search_paths :只继承父target的searchPaths 
    

    例如:

    target 'App' do
       target 'AppTests' do 
          inherit! :search_paths 
        end 
    end
    
    Target配置

    platform: 两个参数。一个是name, 一个是target

    name属性
    osx for OS X, :ios for iOS, :tvos for tvOS, or :watchos for watchOS.
    
    target:版本
    

    例如:

    platform :ios, '4.0'
    platform :ios
    
    inhibit_all_warnings : 忽略所有库中的警告,也可以指定某一个具体库的警告。

    例如:

    //全部忽略
    platform :ios, '8.0'
    
    inhibit_all_warnings!
    
    source 'https://github.com/CocoaPods/Specs.git'
    
    target 'TestPod' do
    
      pod 'SummerOCProjectFrame', '~> 0.0'
    
    end
    
    //某一个忽略
    pod 'SummerOCProjectFrame', '~> 0.0', :inhibit_warnings => true
    
    Source : 可以指定CocoaPods Master Repository,也可以自定义的Repository。

    例如:

    source 'https://github.com/artsy/Specs.git'
    source 'https://github.com/CocoaPods/Specs.git'
    
    pre_install:在pod下载完初始化前可以通过它做逻辑处理。

    例如:

    pre_install do |installer|
      # Do something fancy!
    end
    
    post_install:在形成project后写入本地前可以通过它做逻辑处理。

    比如设置target的build setting, 代码如下:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['GCC_ENABLE_OBJC_GC'] = 'supported'
        end
      end
    end
    
    def name end。 如果project依赖的库很多,比如有自己开发的库,有第三方的库,可以对这些库进行分类。例如:
    def myPods
    pod xxx
    pod xxx1
    pod xxx2
    end
    
    def thirdPods
    pod yyy
    pod yyy1
    pod yyy2
    end
    
    target 'xxx' do
      myPods
      thirdPods
    end
    

    其他还可阅读:

    number1
    number2

    相关文章

      网友评论

          本文标题:Pod小知识点

          本文链接:https://www.haomeiwen.com/subject/umgiaftx.html