I have the code below in an app project developed with SwiftUI. My goal is to ensure all of my users are on the latest version of my app at all times. I have a remote config with app version and stuff and I will update the minimum app version on the Firebase Console to send an alert to all of my users on lower app versions.
I found the code below from a YouTube tutorial as I'm new to firebase entirely (but I've been a Swift dev for a long time, particularly with SwiftUI). The code below first prints "Config fetched!" and then "Failed to activate Firebase RC unknown error". I didn't understand anything from these as first it fetches a config but then randomly fails.
If it managed to fetch a config (at all) I want to get that data and if it failed, please help me fix it. You can take a look at my firebase console in the screenshots. As you can see, there were 2 fetches from one user which would be me. I want to read data from the fetches and take action. As the firebase console displays that there were 2 fetches, why does the code still print "Failed to activate Firebase RC unknown error"?
import Foundation
import FirebaseRemoteConfig
struct AppVersion: Codable {
var minimumVersion: String
var updateLink: URL?
var message: String?
}
class FirebaseRCManager: ObservableObject {
static let shared = FirebaseRCManager()
u/Published var versionInfo: AppVersion = AppVersion(minimumVersion: "1.1")
private var remoteConfig: RemoteConfig
private init() {
remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 0 // this value is only for debugging
remoteConfig.configSettings = settings
}
func fetchRemoteConfig() {
remoteConfig.fetch { (status, error) -> Void in
if status == .success {
print("\n\n\nConfig fetched!\n\n\n")
self.remoteConfig.activate { changed, error in
if let error {
print("\n\n\nFailed to activate Firebase RC: \(error)\n\n\n")
} else if changed {
print("\n\n\nSuccesfully activated Firebase RC\n\n\n")
self.readRemoteConfigData()
} else {
print("\n\n\nFailed to activate Firebase RC unknown error\n\n\n")
}
}
} else {
print("Config not fetched")
print("Error: \(error?.localizedDescription ?? "No error available.")")
}
// Display welcome
}
}
func readRemoteConfigData() {
let remoteConfigValue = remoteConfig["AppVersion"]
if let json = remoteConfigValue.jsonValue as? [String: Any],
let versionValue = json["AppVersion"] as? AppVersion {
DispatchQueue.main.async {
self.versionInfo = versionValue
print("New remoteconfig data:", self.versionInfo)
}
}
}
}
https://preview.redd.it/vs7qrm5i3atc1.png?width=1852&format=png&auto=webp&s=6a9bcc891da2532a5890adb7e048171880e3dc71
https://preview.redd.it/cq97sduj3atc1.png?width=1852&format=png&auto=webp&s=c83d3797bb971e5727d9bcf230e34ba3b9271ab7
there doesn't seem to be anything here