Resolve FBRetainCycleDetector issues after integrating App Monitor with a pod

更新时间:
复制 MD 格式

Problem description

Integrating App Monitor with a pod also imports FBRetainCycleDetector, which causes the following issues:

  • Issue 1: A compilation error occurs for FBRetainCycleDetector: Cannot initialize a parameter of type 'id<NSCopying> _Nonnull' with an rvalue of type 'Class'. 10846568-5404d33c0b929fa9.webp

  • Issue 2: An error occurs when the application switches to the background. IMG_6120.JPG

Solution

Add the following code to the end of your Podfile:

post_install do|installer|
   # Resolve Issue 1
   find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
       "layoutCache[currentClass] = ivars;", "layoutCache[(id)currentClass] = ivars;")
   # Resolve Issue 2
   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

The output is similar to the following.

Run Pod install again.

Applies to

  • Crash Analytics

  • App Performance Analytics