Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Firebase Remote Config Tutorial for iOS

In this Firebase Remote Config tutorial for iOS, you'll learn how to make changes to your iOS app on the fly without resubmitting to the App Store.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5263-firebase-remote-config-tutorial-for-ios

can you add an example on how to test and mock the firebase configuration? i need to add a unit test for this, but can’t find a example to mock the response from firebase

@tkerpelman Can you please help with this when you get a chance? Thank you - much appreciated! :]

There is a small (but dangerous) bug in the code as it is written. When creating the app defaults the code is allowing [String: Any**?**] as follows:
let appDefaults: [String: Any?] = [
ValueKey.appPrimaryColor.rawValue : “#FBB03B
]

and then attempts to convert that on the fly when setting the defaults to [String: NSObject] as follows:
RemoteConfig.remoteConfig().setDefaults(appDefaults as? [String: NSObject])

The bug is that if you set any of the values to nil (as is permitted) it cannot convert the nil to NSObject and thus uses nil for all the defaults.

This bit me as I use remote config extensively throughout our app with hard coded defaults to allow us to remotely config things in the future but all of the defaults were now empty unless the parameter had been set in firebase.

Just thought I’d warn others :slight_smile:

Wow! Good catch! I didn’t think about that case. I’m curious; how did you address the problem?

func activateDebugMode() {
if let debugSettings = RemoteConfigSettings(developerModeEnabled: true) {
RemoteConfig.remoteConfig().configSettings = debugSettings
}
}

That causes this error:

/Users/azavatone/Developer/Planet-Tour/Planet-Tour -Starter/Planet Tour/Utilities/RCValues.swift:42:8: Initializer for conditional binding must have Optional type, not ‘RemoteConfigSettings’

Any ideas?

Huh. Looks like somewhere along the way, the team make this non-failable. Anyway, this is a simple fix; just remove the if {} block.

  func activateDebugMode() {
    let debugSettings = RemoteConfigSettings(developerModeEnabled: true)
    RemoteConfig.remoteConfig().configSettings = debugSettings

  }

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!