简体   繁体   English

如何使用标志禁用Crashlytics iOS库?

[英]How to disable Crashlytics iOS library using a flag?

I am using latest Crashlytics library for iOS. 我正在使用适用于iOS的最新Crashlytics库。 I am looking to disable crashlytics using a single flag. 我希望使用单个标志禁用crashlytics。 How can I do that? 我怎样才能做到这一点?

PS: I am not using set API key method as per new SDK integration guidelines. PS:我没有按照新的SDK集成指南使用set API密钥方法。 (integrated using MAC app) (使用MAC应用程序集成)

Are you trying to prevent Crashlytics from running, or prevent the SDK from getting compiled in at all? 您是在尝试阻止Crashlytics运行,还是阻止SDK进行编译?

To prevent it from running, you can not make the Crashlyitcs call to get it going, generally done in your app delegate. 为了防止它运行,你不能通过Crashlyitcs调用来实现它,通常在你的app委托中完成。

For example, if you're using Crashlytics before Fabric, just comment out the following line: 例如,如果您在Fabric之前使用Crashlytics,只需注释掉以下行:

[Crashlytics startWithAPIKey:<your key>];

If you are using Fabric, you'd want to comment out the following line: 如果您使用的是Fabric,则需要注释掉以下行:

[Fabric with:@[CrashlyticsKit]];

If you're using another Fabric service, remove 'CrashlyticsKit' from the services for Fabric to launch with. 如果您正在使用其他Fabric服务,请从Fabric服务中删除“CrashlyticsKit”以启动。 So for example, you'd want to change: 例如,您想要更改:

[Fabric with:@[TwitterKit, CrashlyticsKit]];

to: 至:

[Fabric with:@[TwitterKit]];

Since you want this done with a flag, there are a number of ways to go about this, One way is to use a processor macro. 由于您希望通过标志完成此操作,因此有许多方法可以解决此问题,一种方法是使用处理器宏。 For example, if you're just trying to disable Crashlytics while running in XCode, you can use DEBUG, a preprocessor macro that's set to 1 in XCode projects by default, in the following way: 例如,如果您只是在XCode中运行时尝试禁用Crashlytics,则可以使用DEBUG,默认情况下在XCode项目中设置为1的预处理器宏,方式如下:

#if DEBUG == 0 [Crashlytics startWithAPIKey:<your key>]; #endif

You can add your own preprocessor macros for whatever contexts you'd like by opening your project file (.xcodeproj) in XCode, select your target, select the "Build Settings" tab, scroll to the "Apple LLVM 6.0 - Preprocessing" section, and change the entries under "Preprocessor Macros". 您可以通过在XCode中打开项目文件(.xcodeproj),为您想要的任何上下文添加自己的预处理器宏,选择目标,选择“Build Settings”选项卡,滚动到“Apple LLVM 6.0 - Preprocessing”部分,并更改“预处理器宏”下的条目。 You can add them for any project configuration, however you'd like. 您可以为任何项目配置添加它们,但是您可以。

Swift language also supports conditional compilation : Swift语言还支持条件编译

#if FABRIC
Fabric.with([Crashlytics.self])
#endif

Define FABRIC as Swift compiler flag in Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags : Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags中将FABRIC定义为Swift编译器Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags

Swift编译器 - 自定义标志

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM