34

The only way to debug Firebase is to pass -FIRAnalyticsDebugEnabled on arguments passed on launch.

It's working in debug mode with my iOS device connected but I would like to deploy an AdHoc build so QA can test it without Xcode.

But it seems arguments aren't passed at launch when Xcode archives a build.

Any solution? Thanks.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Antoine Gamond
  • 802
  • 1
  • 10
  • 19

4 Answers4

68

I found hack solution for this, try it in your application:didFinishLaunchingWithOptions: or override AppDelegate’s init:

Objective-C:

NSMutableArray *newArguments = [NSMutableArray arrayWithArray:[[NSProcessInfo processInfo] arguments]];
[newArguments addObject:@"-FIRDebugEnabled"];
[[NSProcessInfo processInfo] setValue:[newArguments copy] forKey:@"arguments"];

Swift:

var newArguments = ProcessInfo.processInfo.arguments
newArguments.append("-FIRDebugEnabled")
ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")
Dre Sid
  • 749
  • 5
  • 7
  • 5
    This is definitely hacky solution but it works. Really helped me to make AdHoc builds for QA engineers to debug analytics events easily. Thanks! – xZenon Jul 25 '18 at 19:00
  • Does this still work? I have tried the swift code and it does not work for me. – SimpleApp Nov 05 '18 at 13:38
  • 3
    @SimpleApp Yes, it does work. Check that you put this code before Firebase initializations. I prefer to put it early in `application:didStartWithOptions:` and it works fine. – xZenon Dec 20 '18 at 13:13
  • 2
    @SimpleApp There is a confusion between `-FIRAnalyticsDebugEnabled` and `-FIRDebugEnabled`. It works with `-FIRAnalyticsDebugEnabled` in my case – Axel Guilmin Apr 09 '19 at 17:32
  • 1
    Thanks a lot. Actually i need to put your code before initializing Firebase. – Luan Si Ho Aug 13 '19 at 10:38
  • 2
    Google seems to have worked around this, and adding it manually no longer works. – Claus Jørgensen Sep 30 '19 at 08:17
  • 1
    @ClausJørgensen I tried it and it works as expected after more than 4 years. Sad is that there is no official solution from Google itself. – Deny Apr 06 '22 at 05:22
  • @Deny does it work on your side? I'm not able to enable the debug mode programmatically anymore ... – arcangel06 Aug 14 '23 at 08:30
  • 1
    @arcangel06 Nope. I can confirm it's not working anymore. – Deny Aug 24 '23 at 16:26
13

Just some additions to the most upped answer: I would do something like this

#if DEBUG
     var newArguments = ProcessInfo.processInfo.arguments
        newArguments.append("-FIRDebugEnabled")
        ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")
#endif

to keep it to debug. This takes that you set up -DDEBUG in "Other Swift Flags" in Build Settings. (you need to set this for the Debug value, of course.

And then remember to put the code snippet BEFORE you initialize Firebase :-)

Nicolai Harbo
  • 1,064
  • 12
  • 25
11

In addition to proposition above:

  • Add xcconfig files for each build mode (ie: Debug, Adhoc and Release): https://www.appcoda.com/xcconfig-guide
  • Add in all config files: FIREBASE_DEBUG_ENABLED = YES or NO (ie: YES everywhere except Release)
  • Add to your Info.plist file an entry with key: FirebaseDebugEnabled, and string value: $(FIREBASE_DEBUG_ENABLED)
  • In your AppDelegate.m, in didFinishLaunchingWithOptions method, add the following statement:

Objective-C

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];   
NSDictionary *plistConfig = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

// Firebase   
BOOL isFirebaseDebugEnabled = [[plistConfig valueForKey:@"FirebaseDebugEnabled"] boolValue];

if (isFirebaseDebugEnabled) {
    NSLog(@"Firebase debug enabled.");
    NSMutableArray *newArguments = [NSMutableArray arrayWithArray:[[NSProcessInfo processInfo] arguments]];
    [newArguments addObject:@"-FIRAnalyticsDebugEnabled"];
    [newArguments addObject:@"-FIRDebugEnabled"];
    [[NSProcessInfo processInfo] setValue:[newArguments copy] forKey:@"arguments"];   
}

[FIRApp configure];

Swift 4.2

if  let path = Bundle.main.path(forResource: "Info", ofType: "plist"),
    let plist = FileManager.default.contents(atPath: path),
    let preferences = try? PropertyListSerialization.propertyList(from: plist, options: .mutableContainersAndLeaves, format: nil) as? [String:AnyObject],
    let isFirebaseDebugEnabled = preferences["FirebaseDebugEnabled"] as? Bool
{
    if isFirebaseDebugEnabled {
        var args = ProcessInfo.processInfo.arguments
        args.append("-FIRAnalyticsDebugEnabled")
        args.append("-FIRDebugEnabled")
        ProcessInfo.processInfo.setValue(args, forKey: "arguments")
    }
}

You can build your app choosing in the target scheme, in Run section, the build config you want to use (default: Debug), and so, try to run your app in Adhoc and Release modes.

Leon
  • 410
  • 2
  • 14
VincentCATILLON
  • 136
  • 1
  • 4
0

Currently there is no way to turn on Debug mode in AdHoc build or Release build and it is intentional. The DebugView is only for development. Once you build the app, you can only check the real traffic, that is 2-4 hours after running.

adbitx
  • 2,019
  • 8
  • 13