基于 advice ,我想使用 Firebase Remote Config 管理 API key 避免像 google_maps_flutter 这样的硬编码 API key 建议。它有一个像这样的 AppDelegate.swift
:
import UIKit
import Flutter
import GoogleMaps
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("YOUR KEY HERE")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
如何修改以上内容以从 Firebase Remote Config 获取 API key ,然后将其传递给 GMSServices
?
最佳答案
基于此article ,我想到了:
import UIKit
import Firebase
import Flutter
import GoogleMaps
//import os.log
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
RemoteConfig.remoteConfig().fetchAndActivate() { status, error in
let apiKey : String = RemoteConfig.remoteConfig()["Google_Maps_SDK_for_iOS_API_KEY"].stringValue ?? "MISSING";
// os_log("Google_Maps_SDK_for_iOS_API_KEY = '%@'", apiKey)
GMSServices.provideAPIKey(apiKey)
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
有没有更好的办法?
关于ios - 如何在 AppDelegate.swift 中使用 Firebase Remote Config?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60385672/