B4i Library Firebase RemoteConfig

This is a wrapper of Firebase RemoteConfig library for B4i. You can find the B4A version here. I made this for @Jack Cole and he gave me permission to post this in forum to help other users.

iFirebaseRemoteConfig

Wrapper:
@Biswajit
Version: 1.1
  • FirebaseRemoteConfig
    • Events:
      • ActivatedWithCompletion (error As String)
      • FetchedAndActivatedWithCompletion (status As Int, error As String)
      • FetchedWithCompletion (status As Int, error As String)
      • FetchedWithExpirationDuration (status As Int, error As String)
      • InitializationFailed (error As String)
      • Initialized
    • Fields:
      • FIRRemoteConfigError_InternalError As Int
      • FIRRemoteConfigError_Throttled As Int
      • FIRRemoteConfigError_Unknown As Int
      • FIRRemoteConfigFetchAndActivateStatus_Error As Int
      • FIRRemoteConfigFetchAndActivateStatus_SuccessFetchedFromRemote As Int
      • FIRRemoteConfigFetchAndActivateStatus_SuccessUsingPreFetchedData As Int
      • FIRRemoteConfigFetchStatus_Failure As Int
      • FIRRemoteConfigFetchStatus_NoFetchYet As Int
      • FIRRemoteConfigFetchStatus_Success As Int
      • FIRRemoteConfigFetchStatus_Throttled As Int
      • FIRRemoteConfigSource_Default As Int
      • FIRRemoteConfigSource_Remote As Int
      • FIRRemoteConfigSource_Static As Int
    • Functions:
      • ActivateWithCompletionHandler
        Applies Fetched Config data to the Active Config, causing updates to the behavior and
        appearance of the app to take effect (depending on how config data is used in the app).
        This will raise <b>Eventname_ActivatedWithCompletion</b> event.
        Error message will be empty if activation succeeded.
      • AllKeysFromSource (source As Int) As List
        Gets all the parameter keys from a given source.
        The source can be any constant value from FIRRemoteConfigSource.
      • ConfigValueForKey (key As String) As FirebaseRemoteConfigValue
        Gets the config value.
      • ConfigValueForKeySource (key As String, source As Int) As FirebaseRemoteConfigValue
        Gets the config value of a given source. The source can be any constant value from FIRRemoteConfigSource.
      • DefaultValueForKey (key As String) As FirebaseRemoteConfigValue
        Returns the default value of a given key from the default config.
      • EnsureInitializedWithCompletionHandler
        Ensures initialization is complete and clients can begin querying for Remote Config values.
        This will raise <b>Eventname_Initialized</b> event if initialization succeeded. Else <b>Eventname_InitializationFailed</b>.
      • FetchAndActivateWithCompletionHandler
        Fetches Remote Config data and if successful, activates fetched data. Optional completion handler callback
        is invoked after the attempted activation of data, if the fetch call succeeded.
        This will raise <b>Eventname_FetchedAndActivatedWithCompletion</b> event.
        Error message will be empty if fetching succeeded.
        Status can be any constant value from FIRRemoteConfigFetchAndActivateStatus.
      • FetchWithCompletionHandler
        Fetches Remote Config data with a callback.
        This will raise <b>Eventname_FetchedWithCompletion</b> event.
        Error message will be empty if fetching succeeded.
        Status can be any constant value from FIRRemoteConfigFetchStatus.
      • FetchWithExpirationDuration (expirationDuration As Long)
        Fetches Remote Config data and sets a duration that specifies how long config data lasts.
        Override the (default or optionally set minimumFetchInterval property in FIRRemoteConfigSettings) minimumFetchInterval
        for only the current request, in seconds. Setting a value of 0 seconds will force a fetch to the backend.
        This will raise <b>Eventname_FetchedWithExpirationDuration</b> event.
        Error message will be empty if fetching succeeded.
        Status can be any constant value from FIRRemoteConfigFetchStatus.
      • Initialize (eventname As String, callback As Object)
        Initializes the library inside the Application_Start function.
        <b>You should initialize FirebaseAnalytics before initializing this library.</b>
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • KeysWithPrefix (prefix As String) As List
        Returns the set of parameter keys that start with the given prefix, from the default namespace in the active config.
        If prefix is nil or empty, returns all the keys.
      • ObjectForKeyedSubscript (key As String) As FirebaseRemoteConfigValue
        Gets the config value by using object subscripting syntax.
    • Properties:
      • ConfigSettings As FirebaseRemoteConfigSettings
        Set custom config settings.
      • Defaults As Map
        Sets config defaults for parameter keys and values in the default namespace config.
      • LastFetchStatus As Int [read only]
        Last fetch status. The status can be any constant value from FIRRemoteConfigFetchStatus.
      • LastFetchTime As Long [read only]
        Last successful fetch completion time.
  • FirebaseRemoteConfigSettings
    Firebase Remote Config settings
    • Functions:
      • Initialize
        Initialize Firebase Remote Config settings.
      • isDeveloperModeEnabled As Boolean
        Indicates whether Developer Mode is enabled.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
    • Properties:
      • FetchTimeout As Long
        Indicates the default value in seconds to abandon a pending fetch request made to the backend. This value is set for outgoing requests as the timeoutIntervalForRequest as well as the timeoutIntervalForResource on the NSURLSession’s configuration.
      • MinimumFetchInterval As Long
        Indicates the default value in seconds to set for the minimum interval that needs to elapse before a fetch request can again be made to the Remote Config backend. After a fetch request to the backend has succeeded, no additional fetch requests to the backend will be allowed until the minimum fetch interval expires.
        <b>Note:</b> you can override this default on a per-fetch request basis using RemoteConfig.fetchWithExpirationDuration. For E.g. setting the expiration duration to 0 in the fetch request will override the minimumFetchInterval and allow the request to the backend.
  • FirebaseRemoteConfigValue
    This class provides a wrapper for Remote Config parameter values, with methods to get parameter values as different data types.
    • Functions:
      • Initialize (value As Object)
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
    • Properties:
      • BoolValue As Boolean [read only]
        Gets the value as a boolean.
      • DataValue As Byte() [read only]
        Gets the value as a NSData object.
      • DoubleValue As Double [read only]
        Gets the value as a double value.
      • IntValue As Int [read only]
        Gets the value as an int value.
      • JSONValueAsList As List [read only]
        Gets a foundation object (NSArray / List) by parsing the value as JSON.
        This method uses NSJSONSerialization’s JSONObjectWithData method with an options value of 0.
      • JSONValueAsMap As Map [read only]
        Gets a foundation object (NSDictionary / Map) by parsing the value as JSON.
        This method uses NSJSONSerialization’s JSONObjectWithData method with an options value of 0.
      • LongValue As Long [read only]
        Gets the value as a long value.
      • Source As Int [read only]
        Identifies the source of the fetched value. One of the FIRRemoteConfigSource constant.
      • StringValue As String [read only]
        Gets the value as a string.

Installation:
  1. Download the latest libraries from here.
  2. Download the attached ZIP file.
  3. Copy the .framework, .a and .h file to the local build server's Libs folder.
  4. Then copy the XML file to the B4i library folder.
Usage:
  1. Create a new B4i project.
  2. Follow firebase integration tutorial from here
  3. After initializing the Firebase Analytic library initialize this RemoteConfig library.
  4. Please check the RemoteConfig throttling documentation from here.
Update:
  1. V1.1 - Fixed compilation issue with the newer firebase framework.

Click Here to Download
 
Last edited:

Jack Cole

Well-Known Member
Licensed User
Longtime User
Thank you very much Biswajit for this library!

Here is a small example of getting the values. It is a little different from how you do it in the b4a version.

B4X:
minInterstitialGap=cfg.ConfigValueForKey("mg_min_interstitial_gap_ios").IntValue
InterstitialGamePlaysBeforeShow=cfg.ConfigValueForKey("MG_InterstitialGamePlaysBeforeShow_ios").intvalue
adsInGame=cfg.ConfigValueForKey("ads_in_game_ios").BoolValue
 

aaronk

Well-Known Member
Licensed User
Longtime User
I have done it as shown below, but I seem to be getting an unexpected event error in the IDE Logs..

B4X:
Sub Process_Globals
    Private analytics As FirebaseAnalytics        ' iFirebaseAnalytics Lib 2.50
    Public FirebaseRC As FirebaseRemoteConfig    ' iFirebaseRemoteConfig Lib 1.00
End Sub

Private Sub Application_Start (Nav As NavigationController) 'ignore
    analytics.Initialize
    
    ' RemoteConfig
    FirebaseRC.Initialize("RemoteConfig",Me)
    FirebaseRC.EnsureInitializedWithCompletionHandler
End Sub

Sub RemoteConfig_FetchedAndActivatedWithCompletion(status As Int,error As String)
    If status = FirebaseRC.FIRRemoteConfigFetchAndActivateStatus_SuccessFetchedFromRemote Or  status = FirebaseRC.FIRRemoteConfigFetchAndActivateStatus_SuccessUsingPreFetchedData Then
        Log(FirebaseRC.ConfigValueForKey("settings").StringValue)
    Else
        Log(error)
    End If
End Sub

Sub RemoteConfig_Initialized
    FirebaseRC.FetchAndActivateWithCompletionHandler
End Sub

When I use this, I get the following showing in the IDE logs:
Unexpected event (missing RaisesSynchronousEvents): remoteconfig_initialized

If then change the RemoteConfig_Initialized sub to the following (so there is a parameter) then it doesn't seem to show the error message.
B4X:
Sub RemoteConfig_Initialized(test As Object)
    FirebaseRC.FetchAndActivateWithCompletionHandler
End Sub

Should there be a parameter for this event ?

It seems to be working from the testing I have done so far (in debug mode, haven't tried in release mode yet).

From what I have read on the forum we can ignore this message, but want to double check it's not an error and it requires a parameter for this sub.
 

Biswajit

Active Member
Licensed User
Longtime User
That is not an error. You can ignore that. Dont change the sub signature.
 

tufanv

Expert
Licensed User
Longtime User
for people who is trying to implement this: this is not working anymore.
 

Biswajit

Active Member
Licensed User
Longtime User
Do you have this lib to Android? Thanks.
 

asales

Expert
Licensed User
Longtime User
I used this lib until B4A 10.2, but don't works anymore in the new versions. Thanks.
 

Biswajit

Active Member
Licensed User
Longtime User
I used this lib until B4A 10.2, but don't works anymore in the new versions. Thanks.
You should ask the author of that wrapper for a solution/update.
 

Biswajit

Active Member
Licensed User
Longtime User
I used this lib until B4A 10.2, but don't works anymore in the new versions. Thanks.
Hello @asales, I made the android wrapper recently for @tufanv . I got confirmation from him to share the wrapper with other members. I will post the wrapper tomorrow. :)
 

Biswajit

Active Member
Licensed User
Longtime User
The compilation issue has been fixed. Please check the latest update.
 

Biswajit

Active Member
Licensed User
Longtime User
Do you have this lib to Android? Thanks.
 
Top