在我的 firebase 远程配置中,我有一个名为:
"uniquId" = {[1,2,3,4,5,6,7,8,9,10,11,12,14,14]}
我创建了一个 plist:FireStoreRemoteConfig
。
现在我需要从 firebase 远程配置中获取值,并且需要将这些值存储在 plist 中,并且我需要在我的应用程序中使用该数组值。
在我的appdelegate
中:
import FirebaseRemoteConfig
func applicationDidBecomeActive(_ application: UIApplication) {
setUpAppRemoteConfig()
}
func setUpAppRemoteConfig()
{
remoteConfig = RemoteConfig.remoteConfig()
let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: true)
remoteConfig.configSettings = remoteConfigSettings
remoteConfig.setDefaults(fromPlist: "FireStoreRemoteConfig")
fetchConfig()
}
func fetchConfig() {
print("fetched from firestore")
let DataVal = remoteConfig[sampleURLConfigKey].stringValue
print(DataVal)
}
在我的 plist 文件中,我创建了一个参数名为 uniquId
且值为空的数组。
现在每次我启动我的应用程序时。我需要从 firestore 获取值并更新到我的 plist。这样我就可以在我的应用程序中使用这些值。
现在,当我在 func fetchConfig() {
中打印 print(DataVal)
时,值没有出现。
最佳答案
你走在正确的道路上。 fetchConfig()
中仅缺少少量代码。您尚未从远程配置中获取值或数据。
您更新后的代码应如下所示:
func fetchConfig() {
// You can give your required duration
var expirationDuration = 3600
if remoteConfig.configSettings.isDeveloperModeEnabled {
expirationDuration = 0
}
remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void in
if status == .success {
print("Config fetched!")
self.remoteConfig.activateFetched()
} else {
print("Config not fetched")
print("Error \(error!.localizedDescription)")
}
let DataVal = self.remoteConfig[self.sampleURLConfigKey].stringValue
// You can print and check your DataVal.
}
关于ios - 需要将 firebase 远程配置中的值更新到我的 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55057554/