尝试将Firebase添加到iOS应用程序,但无法添加初始化代码

6ljaweal  于 2023-06-30  发布在  iOS
关注(0)|答案(2)|浏览(151)

我目前正在按照以下步骤将Firebase添加到此链接上的iOS应用程序:https://console.firebase.google.com/u/1/project/fir-198a3/overview
我已经能够成功地按照步骤,直到达到我需要添加“初始化代码”的部分。它指出我需要在主AppDelegate类下面添加代码。但是在我的.xcworkspace文件(使用terminal添加Cocoapods后创建的文件)中,我没有看到任何原始文件中的代码。
我的问题是:当您的应用启动时,我应该如何添加以连接Firebase?

import UIKit
import Firebase
content_copy

This is the code I am supposed to copy: (I am running the latest Xcode version)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
      [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
content_copy

    return true
  }
}
siv3szwd

siv3szwd1#

尝试以下操作,以便在应用启动时连接到Firebase:

import SwiftUI
import Firebase

@main
struct TestApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        FirebaseApp.configure()
        return true
    }
}
n9vozmp4

n9vozmp42#

React Native AppFile ./ios/../AppDelegate.mm

#import "AppDelegate.h"
#import <Firebase.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  // Other config ...
}

相关问题