Open jesus-mg-ios opened 1 year ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
See also #11190
This is possible today, here is an example:
FirebaseOptions
, and fill it with the respective configuration values from the GoogleService-Info.plist
file for your project.import Foundation
import FirebaseCore
extension FirebaseOptions {
static var `default`: FirebaseOptions {
let options = FirebaseOptions(googleAppID: "1:23xxxxxxxx",
gcmSenderID: "23xxxxxxxx")
options.clientID = "23xxxxxxxx.apps.googleusercontent.com"
options.apiKey = "AIzxxxxxxx"
options.projectID = "xxxxxxx"
options.storageBucket = "xxxxxxxxx.appspot.com"
options.databaseURL = "https://xxxxxxxxx.firebaseio.com"
return options
}
}
AppDelegate
or main entry point, call FirebaseApp.configure(options: FirebaseOptions.default)
to initialise Firebase:import SwiftUI
import FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure(options: FirebaseOptions.default)
return true
}
}
@main
struct SofiaApp: App {
// register app delegate for Firebase setup
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
RootView()
}
}
}
Also, as mentioned in https://github.com/firebase/firebase-ios-sdk/issues/11190#issuecomment-1523733099, keep in mind that obfuscating the plist file or putting the configuration into code doesn't increase the security of your app. To keep your users' data secure and prevent malicious actors from accessing your backend, you should write solid Security Rules and use App Check.
PS: you can also use this approach to use separate configurations for several environments:
FirebaseOptions
extension (say, create one named FirebaseOptionsProd.swift
, and another one named FirebaseOptionsDev.swift
)FirebaseOptions<environment>.swift
files are assigned to the respective build target.
Description
We want to change fir options to configure the firebase app, from a dictionary not from a plist.
API Proposal
FirOptions(_ map: [String: Any]), in case that this map is empty or does not include some keys, include them by default maybe (?)
Firebase Product(s)
AB Testing, Analytics, App Check, App Distribution, Authentication, Crashlytics, Database, DynamicLinks, Firestore, Functions, In-App Messaging, Installations, Messaging, Performance, Remote Config, Storage