前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Pods组件化手动集成第三方(swift)

Pods组件化手动集成第三方(swift)

作者头像
gwk_iOS
发布2020-05-18 16:08:54
1.9K2
发布2020-05-18 16:08:54
举报
文章被收录于专栏:coding...coding...

失踪人口回归

使用组件化也有一段时间了,碰到不少问题,但也算是给解决了,总结一下手动引入第三方组件的一些问题,个人是用Swift,OC的解决方式就没有实践过。 .podspec 中以 subspec 的方式 为主,主要包含微信、支付宝、微博、极光推送、友盟这几种

微信

微信需要引入 .a 和 .h 文件

.h文件使用 source_files

.a文件使用vendored_libraries

原目录如下

微信目录

代码语言:javascript
复制
Pod::Spec.new do |s|
  s.name             = 'xxx-BaseCore'
  s.version          = '1.0.7'
  s.summary          = '基础组件'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
基础组件
                       DESC

  s.homepage         = 'homepage'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '139391025@qq.com' => '139391025@qq.com' }
  s.source           = { :git => 'git@xxx.git', :tag => s.version.to_s }

  s.ios.deployment_target = '11.0'
  s.swift_version = '5.0'
  s.source_files = 'xxx-BaseCore/Classes/**/*'
  s.default_subspec = "Core"

  s.resource_bundles = {
          'xxx-BaseCore' => [
          'xxx-BaseCore/Assets/*{.storyboard,.xcassets}',
          'xxx-BaseCore/Assets/**/*']
  }
  s.static_framework = true
  s.frameworks = 'UIKit'
  
  # 核心模块
  s.subspec 'Core' do |subspec|
    subspec.dependency 'RxSwift'                  , '4.5.0'
    subspec.dependency 'RxGesture'                , '2.2.0'
    subspec.dependency 'RxDataSources'            , '3.1.0'
    subspec.dependency 'Moya/RxSwift'             , '13.0'
    subspec.dependency 'ObjectMapper'             , '3.4.2'
  end
  
  # 微信模块
  s.subspec 'WXManager' do |subspec|
    subspec.dependency 'xxx-BaseCore/Core'
    subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony'
    subspec.libraries = 'z', 'sqlite3.0', 'c++'
    subspec.source_files = 'xxx-BaseCore/WXManager/*.h'
    subspec.vendored_libraries = 'xxx-BaseCore/WXManager/libWeChatSDK.a'
  end

end

支付宝

支付宝需要引入 .framework 和 .h 文件

目录与微信一致

.framework文件使用 vendored_frameworks

.h文件使用source_files 需要注意的是要将framework中的.h文件都引入

代码语言:javascript
复制
  # 支付宝模块
  s.subspec 'AliPayManager' do |subspec|
    subspec.dependency 'xxx-BaseCore/Core'
    subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony'
    subspec.libraries = 'z', 'sqlite3.0', 'c++'
    subspec.source_files = 'xxx-BaseCore/AliPayManager/*','xxx-BaseCore/AliPayManager/AlipaySDK.framework/Headers/*.h'
    subspec.vendored_frameworks = 'xxx-BaseCore/AliPayManager/AlipaySDK.framework'
    subspec.resources = ['xxx-BaseCore/AliPayManager/AlipaySDK.bundle']

  end

微博

与微信基本一致,但要注意的是需要添加资源文件

代码语言:javascript
复制
# 微博模块
  s.subspec 'WeiboManager' do |subspec|
    subspec.dependency 'xxx-BaseCore/Core'
    subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony'
    subspec.libraries = 'z', 'sqlite3.0', 'c++'
    subspec.source_files = 'xxx-BaseCore/WeiboManager/*.h'
    subspec.vendored_libraries = 'xxx-BaseCore/WeiboManager/libWeiboSDK.a'
    subspec.resources = ['xxx-BaseCore/WeiboManager/WeiboSDK.bundle']
  end

极光

与微信基本一致,但要住要的是需要添加资源文件

官网下载的.a文件命名可能不规范需要改一下名字

代码语言:javascript
复制
  # 极光推送模块
  s.subspec 'JPush' do |subspec|
    subspec.dependency 'xxx-BaseCore/Core'
    subspec.frameworks = 'CFNetwork', 'CoreFoundation', 'CoreTelephony', 'SystemConfiguration', 'CoreGraphics', 'Foundation', 'UIKit', 'Security', 'UserNotifications'
    subspec.libraries = 'z','resolv'
    subspec.source_files = 'xxx-BaseCore/JPush/*.h'
    subspec.vendored_libraries = 'xxx-BaseCore/JPush/libjcore-noidfa-ios-2.1.4.a','xxx-xxx/JPush/libjpush-extension-ios-1.1.2.a','xxx-BaseCore/JPush/libjpush-ios-3.2.6.a'
  end

友盟

友盟的情况比较特殊,主要是swift集成时有一些麻烦,找了不少资料才将其搞定

目录结构

友盟目录

简单的说就是增加prepare_command 为swift创建modulemap

我这边集成的是友盟的facebook和微信

代码语言:javascript
复制
s.prepare_command = <<-EOF
    # 创建UMCommon Module
    rm -rf xxx/Umeng/UMCommon.framework/Modules
    mkdir xxx/Umeng/UMCommon.framework/Modules
    touch xxx/Umeng/UMCommon.framework/Modules/module.modulemap
    cat <<-EOF > xxx/Umeng/UMCommon.framework/Modules/module.modulemap
    framework module UMCommon {
      umbrella header "UMCommon.h"
      export *
      link "sqlite3.0"
    }
    \EOF
    
    # 创建UMShare Module
    rm -rf xxx/Umeng/UMShare.framework/Modules
    mkdir xxx/Umeng/UMShare.framework/Modules
    touch xxx/Umeng/UMShare.framework/Modules/module.modulemap
    cat <<-EOF > xxx/Umeng/UMShare.framework/Modules/module.modulemap
    framework module UMShare {
      umbrella header "UMShare.h"
      export *
      link "sqlite3.0"
    }
    \EOF
  EOF

子模块内容

代码语言:javascript
复制
  # 友盟
  s.subspec 'Umeng' do |subspec|
      subspec.dependency 'xxx/Core'
      subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony', 'WebKit'
      subspec.libraries = 'z', 'sqlite3.0', 'c++'
      subspec.resources = [
      'xxx/Umeng/UMSocialSDKResources.bundle'
      ]
      subspec.source_files = 'xxx/Umeng/*'

      subspec.vendored_frameworks = [
      'xxx/Umeng/*.framework',
      'xxx/Umeng/SocialLibraries/Facebook/*.framework'
      ]
      
      subspec.vendored_libraries = [
      'xxx/Umeng/SocialLibraries/Facebook/libSocialFacebook.a',
      'xxx/Umeng/SocialLibraries/WeChat/libSocialWeChat.a'
      ]
  end
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 微信
  • 支付宝
  • 微博
  • 极光
  • 友盟
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档