9

I am unable to view analytics debug view after I install the app through TestFlight into my test phone.

I have passed in argument -FIRDebugEnabled, and have tried -FIRAnalyticsDebugEnabled but no luck.

-FIRDebugEnabled -FIRAnalyticsDebugEnabled

If I directly installed the app into my test phone through Xcode, the debug view will be available. But if it's installed through TestFlight, the debug view cannot be seen.

user3135515
  • 101
  • 1
  • 6

4 Answers4

5

This can be done by injecting special flags into Firebase's local storages. -FIRDebugEnabled command line argument is being checked by both: FirebaseCore and FirebaseAnalytics frameworks. While the former is saving the flag into shared UserDefaults, the latter is using APMUserDefaults private class, which can be accessed in runtime:

if let APMUserDefaults = NSClassFromString("APMUserDefaults") as AnyObject?,
   let userDefaults = APMUserDefaults.perform(#selector(getter: UserDefaults.standard))?.takeUnretainedValue() {
   _ = userDefaults.perform(#selector(NSMutableDictionary.setObject(_:forKey:)),
                            with: true, 
                            with: "/google/measurement/debug_mode")
}
UserDefaults.standard.set(true, forKey: "/google/firebase/debug_mode")
  • Nice - this works! You can also trigger this at runtime and then kill and relaunch and it'll be the same as launching with the debug flags. – Jason Moore Aug 10 '22 at 06:56
3

Add following code at the first line of application:didFinishLaunchingWithOptions: method of AppDelegate file

CommandLine.arguments.append(contentsOf: ["-FIRDebugEnabled", "-FIRAnalyticsDebugEnabled"])
Ibnu Sina
  • 59
  • 2
3

Add the following code before FirebaseApp.configure():

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

Then, go to your target's build settings and update Release's Optimization level to No Optimization [-Onone].

After that, upload to TestFlight. This method works for me!

0

An addition to the previous answers and for React Native users looking for this, if you are using a library like react-native-config, you can use an env variable to switch this on/off.

Environment variables file example

ANALYTICS_DEBUG=true

In your AppDelegate.mm, inside the didFinishLaunchingWithOptions method:

  NSString *analyticsDebug = [ReactNativeConfig envFor:@"ANALYTICS_DEBUG"];

  if (analyticsDebug != nil && [analyticsDebug isEqualToString:@"true"]) {
    NSProcessInfo *processInfo = [NSProcessInfo processInfo];
    NSArray *arguments = [processInfo arguments];
    NSMutableArray *newArguments = [NSMutableArray arrayWithArray:arguments];

    [newArguments addObject:@"-FIRDebugEnabled"];
    [newArguments addObject:@"-FIRAnalyticsDebugEnabled"];

    [[NSProcessInfo processInfo] setValue:[newArguments copy] forKey:@"arguments"];
  }

  // Setup Firebase
  [FIRApp configure];

Make sure you setup Firebase after, otherwise this won't work.

Mateo Guzmán
  • 1,206
  • 1
  • 15
  • 27