嘿,兄弟!移动端调试工具Flipper了解一下(下)

内容简介:上期文章讲过关于Flipper在移动端的使用,主要介绍了Android上的使用,本期来讲一下关于iOS上的集成。

传送门:嘿,兄弟!移动端调试工具Flipper了解一下

Objective-C集成指南

初始化Podfile

相比于 Android ,iOS 集成相对简单一些。可以使用 CocoaPods 。新建项目,然后 pod init 初始化 Podfile 文件,并添加 Flipper 的依赖,例如:

project 'democome.xcodeproj'	
source 'https://github.com/facebook/flipper.git'	
source 'https://github.com/CocoaPods/Specs'	
swift_version = "4.1"	
flipperkit_version = '0.14.1'	
target 'democome' do	
  platform :ios, '9.0'	
  pod 'FlipperKit', '~>' + flipperkit_version	
  pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version	
  pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version	
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version	
  # This post_install script adds swift version to yogakit's pod target.	
  # It also adds -DFB_SONARKIT_ENABLED=1 flag to OTHER_CFLAGS, necessary to build expose Flipper classes in the header files	
  post_install do |installer|	
        installer.pods_project.targets.each do |target|	
            if ['YogaKit'].include? target.name	
                target.build_configurations.each do |config|	
                    config.build_settings['SWIFT_VERSION'] = swift_version	
                end	
            end	
        end	
        file_name = Dir.glob("*.xcodeproj")[0]	
        app_project = Xcodeproj::Project.open(file_name)	
        app_project.native_targets.each do |target|	
            target.build_configurations.each do |config|	
              if (config.build_settings['OTHER_CFLAGS'])	
                if !(config.build_settings['OTHER_CFLAGS'].include? '-DFB_SONARKIT_ENABLED=1')	
                  puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'	
                  config.build_settings['OTHER_CFLAGS'] << '-DFB_SONARKIT_ENABLED=1'	
                end	
              else	
                puts 'OTHER_CFLAGS does not exist, assigining it to `$(inherited), -DFB_SONARKIT_ENABLED=1` '	
                config.build_settings['OTHER_CFLAGS'] = '$(inherited) -DFB_SONARKIT_ENABLED=1 '	
              end	
              app_project.save	
            end	
        end	
   end	
end

AppDelegate添加如下代码

FlipperClient *client = [FlipperClient sharedClient];	
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];	
[FlipperKitLayoutComponentKitSupport setUpWithDescriptorMapper: layoutDescriptorMapper];	
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application	
                                               withDescriptorMapper: layoutDescriptorMapper]];	
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];  [client start];	
[client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];	
[client start];

运行效果如下

640?wx_fmt=png

Swift集成指南

初始化Podfile

project 'democome-swift.xcodeproj'	
source 'https://github.com/facebook/flipper.git'	
source 'https://github.com/CocoaPods/Specs'	
swift_version = "4.2.1"	
flipperkit_version = '0.14.1'	
target 'democome-swift' do	
  platform :ios, '9.0'	
  pod 'FlipperKit', '~>' + flipperkit_version	
  # Layout and network plugins are not yet supported for swift projects	
  pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version	
  pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version	
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version	
  # If you use `use_frameworks!` in your Podfile, 	
  # uncomment the below $static_framework array and also 	
  # the pre_install section.  This will cause Flipper and 	
  # it's dependencies to be static and all other pods to 	
  # be dynamic.	
  # $static_framework = ['FlipperKit', 'Flipper', 'Folly',	
  #   'CocoaAsyncSocket', 'ComponentKit', 'DoubleConversion', 	
  #   'glog', 'PeerTalk', 'RSocket', 'Yoga', 'YogaKit', 	
  #   'CocoaLibEvent', 'OpenSSL-Static', 'boost-for-react-native']	
  # pre_install do |installer|	
  #     installer.pod_targets.each do |pod|	
  #       if $static_framework.include?(pod.name)  	
  #         pod.host_requires_frameworks = false	
  #       end	
  #   end	
  # end	
# This post_install script adds -DFB_SONARKIT_ENABLED flag to OTHER_SWIFT_FLAGS, necessary to build swift target	
    post_install do |installer|	
      file_name = Dir.glob("*.xcodeproj")[0]	
      app_project = Xcodeproj::Project.open(file_name)	
      app_project.native_targets.each do |target|	
          target.build_configurations.each do |config|	
            if (config.build_settings['OTHER_SWIFT_FLAGS'])	
              if !(config.build_settings['OTHER_SWIFT_FLAGS'].include? '-DFB_SONARKIT_ENABLED')	
                puts 'Adding -DFB_SONARKIT_ENABLED ...'	
                swift_flags = config.build_settings['OTHER_SWIFT_FLAGS']	
                if swift_flags.split.last != '-Xcc'	
                  config.build_settings['OTHER_SWIFT_FLAGS'] << ' -Xcc'	
                end	
                config.build_settings['OTHER_SWIFT_FLAGS'] << ' -DFB_SONARKIT_ENABLED'	
              end	
            else	
              puts 'OTHER_SWIFT_FLAGS does not exist thus assigning it to `$(inherited) -Xcc -DFB_SONARKIT_ENABLED`'	
              config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -Xcc -DFB_SONARKIT_ENABLED'	
            end	
            app_project.save	
          end	
        end	
    end	
  end

这里需要注意Swift版本,需要和你安装的版本保持一致,否则可能会报错,查看Swift版本命令如下:

xcrun swift -version

AppDelegate添加如下代码

let client = FlipperClient.shared()	
let layoutDescriptorMapper = SKDescriptorMapper(defaults: ())	
FlipperKitLayoutComponentKitSupport.setUpWith(layoutDescriptorMapper)	
client?.add(FlipperKitLayoutPlugin(rootNode: application, with: layoutDescriptorMapper!))	
client?.start()

运行结果类似,不在贴出。

--END--

识别二维码,关注我们

640?wx_fmt=png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值