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.
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")
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 :-)
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.
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.