iOS Pod集成移动监控引入FBRetainCycleDetector的问题处理

问题描述

Pod集成移动监控引入FBRetainCycleDetector,会出现以下问题:

  • 问题一:FBRetainCycleDetector编译报错Cannot initialize a parameter of type 'id<NSCopying> _Nonnull' with an rvalue of type 'Class'10846568-5404d33c0b929fa9.webp

  • 问题二:应用切换到到后台就报错。 IMG_6120.JPG

解决方案

在Podfile的末尾添加以下内容:

post_install do|installer|
   #解决问题一
   find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
       "layoutCache[currentClass] = ivars;", "layoutCache[(id)currentClass] = ivars;")
   #解决问题二
   find_and_replace("Pods/FBRetainCycleDetector/fishhook/fishhook.c",
   "indirect_symbol_bindings[i] = cur->rebindings[j].replacement;", "if (i < (sizeof(indirect_symbol_bindings) /
        sizeof(indirect_symbol_bindings[0]))) { \n indirect_symbol_bindings[i]=cur->rebindings[j].replacement; \n }")
end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
    FileUtils.chmod("+w",name) #add
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
         puts "Fix: " + name
         File.open(name, "w") { |file| file.puts replace }
         STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

系统显示类似如下。

再重新执行Pod install。

适用于

  • 崩溃分析

  • 性能分析