【问题标题】:How to debug Firebase on iOS AdHoc build如何在 iOS AdHoc 构建上调试 Firebase
【发布时间】:2017-09-30 23:28:53
【问题描述】:

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

它在我的 iOS 设备连接的情况下以调试模式工作,但我想部署一个 AdHoc 构建,以便 QA 可以在没有 Xcode 的情况下对其进行测试。

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

有什么解决办法吗?谢谢。

【问题讨论】:

    标签: xcode debugging firebase firebase-analytics adhoc


    【解决方案1】:

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

    目标-C:

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

    斯威夫特:

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

    【讨论】:

    • 这绝对是 hacky 解决方案,但它确实有效。真的帮助我为 QA 工程师制作 AdHoc 构建,以便轻松调试分析事件。谢谢!
    • @SimpleApp 是的,它确实有效。检查您是否将此代码放在 Firebase 初始化之前。我更喜欢早点把它放在application:didStartWithOptions: 中,它工作得很好。
    • @SimpleApp -FIRAnalyticsDebugEnabled-FIRDebugEnabled 之间存在混淆。在我的情况下,它适用于 -FIRAnalyticsDebugEnabled
    • 非常感谢。实际上我需要在初始化 Firebase 之前输入你的代码。
    • Google 似乎已经解决了这个问题,并且手动添加它不再有效。
    【解决方案2】:

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

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

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

    然后记得在初始化 Firebase 之前输入代码 sn-p :-)

    【讨论】:

      【解决方案3】:

      除上述命题外:

      • 为每种构建模式(即:Debug、Adhoc 和 Release)添加 xcconfig 文件https://www.appcoda.com/xcconfig-guide
      • 添加所有配置文件FIREBASE_DEBUG_ENABLED = YESNO(即:YESRelease 之外的所有位置)
      • 在您的 Info.plist 文件中添加一个条目,其键为:FirebaseDebugEnabled,字符串值:$(FIREBASE_DEBUG_ENABLED)
      • 在您的AppDelegate.mdidFinishLaunchingWithOptions 方法中,添加以下语句:

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

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-11
          • 2018-08-12
          • 1970-01-01
          • 2013-02-11
          • 1970-01-01
          相关资源
          最近更新 更多