2015-09-11 87 views
4

我正在使用此问题的解决方案:Cocoapods: turning MagicalRecord logging off在我将CocoaPods更新到最新版本(0.38.2)之前,它已经运行良好。现在,只要我运行pod install命令,它就会返回几个错误。尝试关闭CocoaPods的MagicalRecord登录时发生错误0.38

作为参考,这里是原始Podfile代码段由ANK(link)共享:

post_install do |installer| 
    target = installer.project.targets.find{|t| t.to_s == "Pods-MagicalRecord"} 
    target.build_configurations.each do |config| 
     s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] 
     s = [ '$(inherited)' ] if s == nil; 
     s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug"; 
     config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s 
    end 
end 

我遇到的第一个问题是,project需要与pods_project上Podfile进行更换,所以我做到了。

但是这让我卡住之一是它不承认build_configurations声明,你可以在波纹管控制台错误,请参阅:

... 
Generating Pods project 
[!] An error occurred while processing the post-install hook of the Podfile. 

undefined method `build_configurations' for nil:NilClass 
... 

我用Google搜索这个问题,但一直没找到工作它不是从SO或gitHub或其他站点解决它。我相信可能需要进行一些更改,才能使该代码片段再次在此版本的CocoaPods上工作,所以我想知道是否有人提出了针对此问题的解决方案,或者如果有另一种方法可以关闭登录MagicalRecord(顺便说一句,我使用的是2.2版)。

这里是我的Podfile的最后部分:

post_install do |installer| 
    target = installer.pods_project.targets.find{|t| t.to_s == "Pods-MagicalRecord"} 
    target.build_configurations.each do |config| 
     s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] 
     s = [ '$(inherited)' ] if s == nil; 
     s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug"; 
     config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s 
    end 
end 

任何帮助将广泛赞赏:)

+0

在那个上有什么成就? – Georg

+0

嗨@Georg对不起,但迄今为止没有成功。我只是删除了上面的代码,所以我可以完成pod install命令并生成.xcworkspace文件,但我仍然无法找到一种方法使用CocoaPods 0.38关闭登录 –

回答

1

我发现,你需要通过增加post_install下面一行用"MagicalRecord",而不是"Pods-MagicalRecord"

puts installer.pods_project.targets 

我工作的解决方案代码:

# Turn off Magical Record logging in debug mode - in release mode it is off by default 
target = installer.pods_project.targets.find{|t| t.to_s == "MagicalRecord"} 
target.build_configurations.each do |config| 
    s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] 
    s = [ '$(inherited)' ] if s == nil; 
    # Uncomment one matching your version 
    #s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug"; # MagicalRecord < 2.3 
    #s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug"; # MagicalRecord 2.3+ 
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s 
end