如何调试iOS AdHoc构建上的Firebase?

34

调试Firebase的唯一方法是在启动时通过参数-FIRAnalyticsDebugEnabled传递。

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

但是似乎当Xcode存档构建时,参数不会在启动时传递。

有什么解决方案吗?谢谢。

4个回答

68

我找到了一种非正规的解决方案,可以在你的application:didFinishLaunchingWithOptions:中尝试它,或者重写AppDelegate的init方法:

Objective-C:

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

Swift:

-->

Swift编程语言:

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

5
这绝对是一个"hacky"的解决方案,但它可以工作。确实帮助了我为QA工程师制作AdHoc版本,使得调试分析事件更加容易。谢谢! - xZenon
3
@SimpleApp 是的,它有效。请确认在 Firebase 初始化之前放置此代码。我建议在 application:didStartWithOptions: 中早期放置它,这样可以正常工作。 - xZenon
2
@SimpleApp 在“-FIRAnalyticsDebugEnabled”和“-FIRDebugEnabled”之间存在混淆。在我的情况下,它与“-FIRAnalyticsDebugEnabled”一起使用。 - Axel Guilmin
1
非常感谢。实际上,在初始化 Firebase 之前,我需要放置您的代码。 - Luan Si Ho
2
谷歌似乎已经解决了这个问题,手动添加不再起作用。 - Claus Jørgensen
显示剩余4条评论

13

只是对最新回答的一些补充: 我会做类似于这样的事情

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

保持其可调试性。需要在构建设置中的"其他Swift标志"中设置-DDEBUG(当然,你需要将其设置为Debug值)。

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


12

除了上面提到的建议之外:

  • 为每个构建模式(即Debug、Adhoc和Release)添加xcconfig文件https://www.appcoda.com/xcconfig-guide
  • 所有配置文件中添加FIREBASE_DEBUG_ENABLED = YESNO(即Release以外处处都是YES
  • 在您的Info.plist文件中添加一个键为FirebaseDebugEnabled,值为$(FIREBASE_DEBUG_ENABLED)的条目
  • 在您的AppDelegate.m文件中,在didFinishLaunchingWithOptions方法中添加以下语句:

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")
    }
}

您可以在目标方案中选择构建配置文件,即在 运行 部分中选择您想要使用的构建配置文件 (默认为 调试(Debug)),并尝试以 Adhoc发布(Release) 模式运行您的应用程序。


0

目前在AdHoc版本或发布版本中没有开启调试模式的方法,这是有意为之的。DebugView仅用于开发。一旦您构建了应用程序,您只能检查实际流量,即在运行后2-4小时内。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接