【问题标题】:FirebaseApp.configure() has an error use of unresolved identifier 'FirebaseApp'FirebaseApp.configure() 错误使用未解析的标识符“FirebaseApp”
【发布时间】:2017-06-26 04:45:54
【问题描述】:

所以每次在我的 pod 文件中,我决定在我的应用程序中添加类似 pod 'Firebase/Storage' 和 pod 'Firebase/Core' 的内容,在我的应用程序中,FirebaseApp.configure() 错误使用未解析的标识符 'FirebaseApp' 我的 pod 文件是

https://docs.google.com/document/d/1U7s5StRuNrI_2WtpHSvHhwhA1TMCsQ255dnjDAEhhcE/edit?usp=sharing

【问题讨论】:

    标签: xcode firebase cocoapods firebase-storage


    【解决方案1】:

    我通过使用 FirebaseCore 而不是 Firebase 库解决了这个问题:

    import FirebaseCore
    

    【讨论】:

    【解决方案2】:

    您的 appdelegate 类应如下所示:

    import UIKit
    import Firebase
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
            FIRApp.configure()
            return true
        }
    
        func applicationWillResignActive(_ application: UIApplication) {
            // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
            // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
        }
    
        func applicationDidEnterBackground(_ application: UIApplication) {
            // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
            // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
        }
    
        func applicationWillEnterForeground(_ application: UIApplication) {
            // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
        }
    
        func applicationDidBecomeActive(_ application: UIApplication) {
            // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        }
    
        func applicationWillTerminate(_ application: UIApplication) {
            // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        }
    }
    

    我假设您使用的是 xcode 8 和 swift 3。

    【讨论】:

    • 没问题,我们直接转成swift 2.2就可以了
    • 那么转换后的效果如何? (这让我很紧张)
    • 别担心,我正在更新答案,虽然我认为除了 swift 2.2 应用程序委托之外它仍然是同一件事
    • 仅使用“Firebase/Core”(我唯一可以输入且不会出错)进行了尝试,但 FIRApp.configure() 没有工作,但 FirebaseApp.configure() 工作得很好
    • 所以你导入了 firebase 并且 FirebaseApp.configure() 工作了吗?能否请您向我们展示您的应用委托。
    【解决方案3】:

    就我而言,是因为我使用的是旧版本的 Firebase (3.11.1)

    pod repo update
    pod update
    

    使用 Firebase (4.2.0) 更新我的存储库和我的本地规范存储库后,FirebaseApp 已由 Xcode 解决!

    【讨论】:

    • 谢谢。我关注了当前(03/09/2019)Firebase 文档,但 FirebaseApp.configure() 不起作用。然后我运行了你显示的命令,我看到了(安装 Firebase 5.18.0(原为 3.10.0))。不确定为什么初始 pod 安装会在当前日期安装旧版本。更新后 FirebaseApp.configure() 确实有效。
    【解决方案4】:

    运行 pod update 至少到 Firebase 6.31.1。

    Firebase 在 6.28.0 中进行了更改,暴露了 Xcode 构建竞争条件。更改在 6.31.1 中恢复。详情https://github.com/firebase/firebase-ios-sdk/issues/6341

    【讨论】:

    • 谢谢伙计……这对我有用!按照您的步骤操作后,我只能使用 import Firebase 而无需升级到 FirebaseCore
    【解决方案5】:

    尝试使用 pod 'Firebase' 而不是 pod 'Firebase/Core'

    并检查是否在“pod install”之后安装了 Firebase 4.x

    【讨论】:

      【解决方案6】:

      使用“import FirebaseCore”,而不是“import Firebase”

      【讨论】:

        【解决方案7】:

        这将解决这个问题

         sudo gem install cocoapods 
         pod update
        

        【讨论】:

          【解决方案8】:

          morganchen12 在此GitHub 评论中的解决方案为我解决了同样的问题。我需要为单元测试修改 Podfile(OP 已经完成),然后将 Firebase 添加到 Header Search 路径中。

          为保存,注释为:

          该问题是由测试运行时中重复的 FIRApp 类定义引起的。

          您的 Podfile 应如下所示:

          target "FirebaseDemo" do
            install_pods
          
            target "FirebaseDemoTests" do
              inherit! :search_paths
            end
          end
          

          为了避免缺少必需的模块 Firebase 错误,请将“${PODS_ROOT}/Firebase/Core/Sources”添加到 Xcode 中测试目标的标头搜索路径的末尾。

          【讨论】:

            【解决方案9】:

            我的 pod 文件包含 Firebase/Core 和 Firebase/Auth。

            更新 pod 并没有为我解决问题,我还尝试了 pod 'Firebase'。 It was simply this mistake

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2020-01-23
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多