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

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

微信

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

.h文件使用 source_files

.a文件使用vendored_libraries

原目录如下

49d6f5958d2d68c7181251937bd8ed5b.png
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      = < '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'  endend

支付宝

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

目录与微信一致

.framework文件使用 vendored_frameworks

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

  # 支付宝模块  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

微博

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

# 微博模块  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文件命名可能不规范需要改一下名字

  # 极光推送模块  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集成时有一些麻烦,找了不少资料才将其搞定

目录结构

601b9baa0dc408a45d547d0259df4b5a.png

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

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

s.prepare_command = < 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 < xxx/Umeng/UMShare.framework/Modules/module.modulemap    framework module UMShare {      umbrella header "UMShare.h"      export *      link "sqlite3.0"    }    EOF  EOF

子模块内容

  # 友盟  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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值