如何在iOS AdHoc版本上调试Firebase

Ant*_*ond 13 debugging xcode adhoc firebase firebase-analytics

调试Firebase的唯一方法是-FIRAnalyticsDebugEnabled传递启动时传递的参数.

它在调试模式下工作,我的iOS设备已连接,但我想部署一个AdHoc版本,所以QA可以在没有Xcode的情况下测试它.

但是当Xcode归档构建时,似乎没有在启动时传递参数.

有解决方案吗 谢谢.

小智 31

我找到了hack解决方案,在你的应用程序中尝试:didFinishLaunchingWithOptions:或覆盖AppDelegate的init:

Objective-C的:

NSMutableArray *newArguments = [NSMutableArray arrayWithArray:[[NSProcessInfo processInfo] arguments]];
[newArguments addObject:@"-FIRDebugEnabled"];
[[NSProcessInfo processInfo] setValue:[newArguments copy] forKey:@"arguments"];
Run Code Online (Sandbox Code Playgroud)

迅速:

var newArguments = ProcessInfo.processInfo.arguments
newArguments.append("-FIRDebugEnabled")
ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")
Run Code Online (Sandbox Code Playgroud)

  • 这绝对是hacky解决方案,但它的工作原理.真的帮助我为QA工程师制作了AdHoc版本,以便轻松调试分析事件.谢谢! (3认同)
  • @SimpleApp是的,它确实可以工作。检查您是否将此代码放在Firebase初始化之前。我更喜欢将其放在`application:didStartWithOptions:`中,并且效果很好。 (2认同)
  • @SimpleApp `-FIRAnalyticsDebugEnabled` 和 `-FIRDebugEnabled` 之间存在混淆。在我的例子中,它与“-FIRAnalyticsDebugEnabled”一起使用 (2认同)
  • 多谢。实际上我需要在初始化 Firebase 之前放置你的代码。 (2认同)
  • 谷歌似乎已经解决了这个问题,并且手动添加它不再起作用。 (2认同)
  • @ClausJørgensen 我尝试过,四年多后它按预期工作。遗憾的是谷歌本身没有给出官方解决方案。 (2认同)

小智 7

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];
Run Code Online (Sandbox Code Playgroud)

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")
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以在目标方案中选择构建您的应用程序,在Run部分中,您要使用的构建配置(默认值:)Debug,因此,尝试在AdhocRelease模式下运行您的应用程序。


Nic*_*rbo 6

只是对最高的答案进行了一些补充:我会做这样的事情

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

以保持调试。这需要您-DDEBUG在 Build Settings 的“Other Swift Flags”中进行设置。(当然,您需要为 Debug 值设置此项。

然后记得在初始化 Firebase 之前放置代码片段 :-)


adb*_*itx 0

目前无法在 AdHoc 构建或 Release 构建中打开调试模式,这是故意的。DebugView 仅用于开发。构建应用程序后,您只能查看实际流量,即运行后 2-4 小时。