您的位置:首页 > 其它

use firebase remote config

2018-03-03 07:20 302 查看

Use Firebase Remote Config on iOS

You can use Firebase Remote Config to define parameters in your app and update their values in the cloud, allowing you to modify the appearance and behavior of your app without distributing an app update.

Add Remote Config to your app

Install the Firebase SDK.
Add the following dependency to your Podfile:
pod 'Firebase/RemoteConfig'
Run 
pod install
 and open the created 
.xcworkspace
 file.
Import the Firebase module in your 
UIApplicationDelegate
:

SWIFT

OBJECTIVE-C

@import Firebase;
Configure a 
FirebaseApp
 shared instance, typically in your application's 
application:didFinishLaunchingWithOptions:
 method:

SWIFT

OBJECTIVE-C

// Use Firebase library to configure APIs
[FIRApp configure];
Create the singleton Remote Config object, as shown in the following example:

SWIFT

OBJECTIVE-C

self.remoteConfig = [FIRRemoteConfig remoteConfig];This object is used to store in-app default parameter values, fetch updated parameter values from the service, and control when fetched values are made available to your app. To learn more, see Remote Config API Overview.

Set in-app default parameter values

You can set in-app default parameter values in the Remote Config object, so that your app behaves as intended before it connects to the Remote Config Server, and so that default values are available if none are set in the service.Define a set of parameter names, and default parameter values using an NSDictionary object or a plist file.
Add these values to the Remote Config object using setDefaults:.

Get parameter values to use in your app

Now you can get parameter values from the Remote Config object. If you later set values in the Remote Config service, fetch them, and then activate them, those values are available to your app. Otherwise, you get the in-app parameter values configured using setDefaults:. To get these values, call the configValueForKey: method, providing the parameter key as an argument.

Connect your app in the Firebase console

In the Firebase console, add your app to your Firebase project.

Set parameter values in the service (as needed)

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. To learn more, see Remote Config Parameters and Conditions.

Fetch and activate values from the service (as needed)

To fetch parameter values from the Remote Config Server, call the fetchWithCompletionHandler:or fetchWithExpirationDuration:completionHandler: method. Any values that you set on the Remote Config Server are fetched and cached in the Remote Config object.
To make fetched parameter values available to your app, call the activateFetched method.
Because these updated parameter values affect the behavior and appearance of your app, you should activate the fetched values at a time that ensures a smooth experience for your user, such as the next time that the user opens your app.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: