我目前正在按照此链接上的步骤将 Firebase 添加到 iOS 应用程序:https://console.firebase.google.com/u/1/project/fir-198a3/overview
我已经能够成功地按照这些步骤进行操作,直到到达需要添加“初始化代码”的部分。它指出我需要在主 AppDelegate 类下面添加代码。但在我的 .xcworkspace 文件(使用终端添加 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
}
}
尝试此操作,在应用程序启动时连接到 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
}
}
React Native 应用程序文件./ios/../AppDelegate.mm
#import "AppDelegate.h"
#import <Firebase.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
// Other config ...
}
文件名请告诉我我的要求......