How to disable Crashlytics iOS library using a flag?
Asked Answered
O

2

5

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

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

Octans answered 8/3, 2015 at 20:9 Comment(0)
B
11

Are you trying to prevent Crashlytics from running, or prevent the SDK from getting compiled in at all?

To prevent it from running, you can not make the Crashlyitcs call to get it going, generally done in your app delegate.

For example, if you're using Crashlytics before Fabric, just comment out the following line:

[Crashlytics startWithAPIKey:<your key>];

If you are using Fabric, you'd want to comment out the following line:

[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 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:

#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.

Barclay answered 10/3, 2015 at 17:35 Comment(1)
Thanks for the response. I used the same things you showed here but was not working the other day when I asked question. Then again trying same next day it started working :) (I guess some cache memory or something) Thanks for confirming that this is the solution.Octans
T
3

Swift language also supports conditional compilation:

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

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

Swift Compiler - Custom Flags

Threadgill answered 5/1, 2016 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.