Tuesday, February 16, 2016

[iOS]Cocoapods Packager: publish pods framework from a library

When you created iOS/Mac OS library project as well as the sample app to use the library, one day you want to make the library as a framework:


  1. Install Cocoapods by $ sudo gem install cocoapods
  2. Install Cocoapods packager by $ sudo gem install cocoapods-packager
  3. Create you framework class to include all the public header files
  4. Public the header files by adding them to target library > Build Phases > Copy Files, you have to import those files in the library project like  #import <FRAMEWORK_NAME/CLASS_NAME.h> instead of #import "CLASS_NAME.h", otherwise you would get a lot of duplicated constants and classes.
  5. Make you .podspec file
    Pod::Spec.new do |s|
      s.name     = 'FRAMEWORK_NAME'
      s.version  = '0.0.1'
      s.license  = 'MIT'
      s.summary  = 'name'
      s.homepage = 'https://github.com'
      s.authors  = { 'Phunware' => 'info@company.com' }
      s.source   = { :git => 'https://github.com/**.git', :branch => 'BB'  }
      s.requires_arc = true
      s.dependency 'PODS_NAME'
      s.default_subspec = 'Production'
    
      s.ios.deployment_target = '8.0'
    
      s.public_header_files = 
      'FRAMEWORK_NAME/**/PUBLIC_CLASS.h',
      'FRAMEWORK_NAME/**/PUBLIC_CLASS.h'
    
      s.source_files  = 'FRAMEWORK_NAME/**/*.{h,m}'
      s.xcconfig      = { 'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/PWCore/**"',
      'ENABLE_BITCODE' => 'YES' }
    
      s.subspec 'Production' do |prod|
        prod.public_header_files = 
      'FRAMEWORK_NAME/**/PUBLIC_CLASS.h',
      'FRAMEWORK_NAME/**/PUBLIC_CLASS.h'
    
        prod.source_files  = 'FRAMEWORK_NAME/**/*.{h,m}'
        prod.prefix_header_contents = <<-eos data-blogger-escaped-__objc__="" data-blogger-escaped-configuration_production="" data-blogger-escaped-define="" data-blogger-escaped-end="" data-blogger-escaped-endif="" data-blogger-escaped-eos="" data-blogger-escaped-foundation="" data-blogger-escaped-ifdef="" data-blogger-escaped-import="" data-blogger-escaped-pre="" data-blogger-escaped-uikit="">
  6. Then you can make the framework locally by $ pod package FRAMEWORK_NAME.podspec --subspecs=Production --spec-sources=PRIVATE_SPECS --verbose
  7. Valid your framework before publishing by $ pod spec lint FRAMEWORK_NAME.podspec --sources= PRIVATE_SPECS --use-libraries --verbose --allow-warnings
  8. Publish you framework to cocoapods repo $ pod trunk push FRAMEWORK_NAME.podpec

Note: When do package locally you may meet issues, just upgrade the cocoapads to latest version. Like upgrade ruby to the version you want by $ rvm upgrade current_version version_you_wanted

No comments:

Post a Comment