Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift/iOS - Firebase Remote Config fetch values never completes

Below is a class implemented to fetch remote config values from the Firebase console, however when calling fetch cloud values, the completion block never executes (i.e. If I break in the completion block, Xcode never breaks). All documentation seems to be outdated now and I can't see what I am doing wrong.

@objc class RemoteConfigValues: NSObject {

    @objc static let sharedInstance = RemoteConfigValues()

    private override init() {
        super.init()
        let settings = RemoteConfigSettings()

        //WARNING THIS IS FOR DEBUG ONLY
        settings.minimumFetchInterval = 0
        RemoteConfig.remoteConfig().configSettings = settings
        loadDefaultValues()
        fetchCloudValuesWith(fetchInterval: 0.0)
    }

    func loadDefaultValues() {
        let appDefaults: [String: Any?] = [
            RemoteConfigKeys.senseAdType.rawValue: String("A"),
            RemoteConfigKeys.sensePromotionButton.rawValue: String("BUY NOW")
        ]
        RemoteConfig.remoteConfig().setDefaults(appDefaults as? [String: NSObject])
    }

    func getInstanceIDToken() {
        InstanceID.instanceID().instanceID { (result, error) in
          if let error = error {
            print("Error fetching remote instance ID: \(error)")
          } else if let result = result {
            print("Remote instance ID token: \(result.token)")
          }
        }
    }

    func fetchCloudValues() {
        RemoteConfig.remoteConfig().fetchAndActivate { (status, error) in
            if let error = error {
                print("Uh-oh. Got an error fetching remote values \(error)")
                return
            }
            print("Retrieved values from the cloud!")
        }
    }

    func fetchCloudValuesWith(fetchInterval: Double) {
        RemoteConfig.remoteConfig().fetch(withExpirationDuration: fetchInterval) { status, error in

            if let error = error {
                print("Uh-oh. Got an error fetching remote values \(error)")
                return
            }

            RemoteConfig.remoteConfig().activate { (error) in
                print("Uh-oh. Got an error fetching remote values \(error?.localizedDescription ?? "")")
            }
            print("Retrieved values from the cloud!")
        }
    }

}

Below are the logs that are printing to the console for Firebase/RemoteConfig

2020-06-11 10:16:20.061816+0100 MyApp[67337:10404626] 6.12.0 - [Firebase/RemoteConfig][I-RCN000062] Loading database at path /Users/dominicbryan/Library/Developer/CoreSimulator/Devices/481BF064-0BC7-404E-836F-A0AB58FD8900/data/Containers/Data/Application/77B9DD80-FFF4-4354-8B30-23E39C794861/Library/Application Support/Google/RemoteConfig/RemoteConfig.sqlite3
2020-06-11 10:16:20.064711+0100 MyApp[67337:10404626] 6.12.0 - [Firebase/RemoteConfig]2020-06-11 10:16:20.065426+0100 MyApp[67337:10404579] <NSProgress: 0x600000f5c5a0> : Parent: 0x0 (portion: 0) / Fraction completed: 1.0000 / Completed: 2203 of 2203
2020-06-11 10:16:20.066622+0100 MyApp[67337:10404626] 6.12.0 - [Firebase/RemoteConfig][I-RCN000039] Starting requesting token.
2020-06-11 10:16:21.164733+0100 MyApp[67337:10404579] 6.12.0 - [Firebase/RemoteConfig][I-RCN000022] Success to get iid : fqcuK-XSZsU.
2020-06-11 10:16:21.166088+0100 MyApp[67337:10404579] 6.12.0 - [Firebase/RemoteConfig][I-RCN000024] Success to get device authentication ID: 5**************7, security token: 7***************8.
2020-06-11 10:16:21.166737+0100 MyApp[67337:10404579] 6.12.0 - [Firebase/RemoteConfig][I-RCN000060] Fetch with user properties completed.
like image 369
Dom Bryan Avatar asked Jun 09 '20 15:06

Dom Bryan


People also ask

How do I set up remote config in Firebase?

In the Firebase console, open your project. Select Remote Config from the menu to view the Remote Config dashboard. Define parameters with the same names as the parameters that you defined in your app.

How do I change the default value of a firebase parameter?

In the Firebase console, open your project. Select Remote Config from the menu to view the Remote Config dashboard. Define parameters with the same names as the parameters that you defined in your app. For each parameter, you can set a default value (which will eventually override the in-app default value) and you can also set conditional values.

What is the default and recommended fetch interval for remote config?

The default and recommended production fetch interval for Remote Config is 12 hours, which means that configs won't be fetched from the backend more than once in a 12 hour window, regardless of how many fetch calls are actually made. Specifically, the minimum fetch interval is determined in this following order:

How do I get in app parameter values from remote config?

Now you can get parameter values from the Remote Config object. If you later set values in the Remote Config backend, fetch them, and then activate them, those values are available to your app. Otherwise, you get the in-app parameter values configured using setDefaults: .


Video Answer


1 Answers

Use your func fetchCloudValuesWith(fetchInterval: Double) instead of using fetchAndActivate:

remoteConfig.fetch(withExpirationDuration: 0) { [weak self] (status, error) in
    //Do your stuffs    
}
like image 138
developervtph Avatar answered Sep 28 '22 00:09

developervtph