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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28931322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:47:25  来源:igfitidea点击:

How to disable Crashlytics iOS library using a flag?

iosobjective-cxcodecrashlytics

提问by user1140780

I am using latest Crashlytics library for iOS. I am looking to disable crashlytics using a single flag. How can I do that?

我正在为 iOS 使用最新的 Crashlytics 库。我希望使用单个标志禁用 crashlytics。我怎样才能做到这一点?

PS: I am not using set API key method as per new SDK integration guidelines. (integrated using MAC app)

PS:我没有按照新的 SDK 集成指南使用设置 API 密钥方法。(使用 MAC 应用程序集成)

回答by Ben Resplendent

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 调用来让它运行,通常在您的应用程序委托中完成。

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. So for example, you'd want to change:

如果您使用其他 Fabric 服务,请从要使用的 Fabric 服务中删除“CrashlyticsKit”。例如,您想更改:

[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

#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". You can add them for any project configuration, however you'd like.

您可以通过在 XCode 中打开项目文件 (.xcodeproj),为您想要的任何上下文添加自己的预处理器宏,选择您的目标,选择“构建设置”选项卡,滚动到“Apple LLVM 6.0 - 预处理”部分,并更改“预处理器宏”下的条目。您可以根据需要为任何项目配置添加它们。

回答by mixel

Swift language also supports conditional compilation:

Swift 语言也支持条件编译

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

Define FABRICas Swift compiler flag in Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags:

定义FABRIC为 Swift 编译器标志Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags

Swift Compiler - Custom Flags

Swift 编译器 - 自定义标志