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



我目前正在按照以下步骤将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 AppFile ./ios/../AppDelegate.mm

#import "AppDelegate.h"
#import <Firebase.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
// Other config ...
}

最新更新