跳转到主要内容
PRODUCT DOCUMENTS

快速找到所需文档,高效完成接入与排障

浏览产品文档与友盟 Skill,展开目录并阅读正文。

iOS 在线参数(云配置) SDK集成文档

远程配置为开发者提供在远程线配置参数,并能通过SDK帮助用户获取实时数据。

概述

远程配置为开发者提供在远程线配置参数,并能通过SDK帮助用户获取实时数据。

适用范围

UMeng组件化SDK适用于iOS 8.0及以上操作系统。

基础功能

初始化

介绍及参数说明

参数

说明

delegate

远程配置的回调通知 请查看UMRemoteConfigDelegate

configSettings

远程配置类 请查看类UMRemoteConfigSettings

接口函数

/**
 *  @brief 远程配置单例
 *  @param delegate  see UMRemoteConfigDelegate
 *  @note 用户初始化时候,
    先调用 remoteConfigWithDelegate:(id<UMRemoteConfigDelegate>)delegate,可以保证上次ready的数据可以回调给用户。
 */
+ (UMRemoteConfig *)remoteConfigWithDelegate:(nullable id<UMRemoteConfigDelegate>)delegate
                          withConfigSettings:(nullable UMRemoteConfigSettings*)configSettings;
+ (UMRemoteConfig *)remoteConfig;

详细集成及示例代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    [UMRemoteConfig remoteConfigWithDelegate:self withConfigSettings:nil];
}

设置本地默认值

介绍及参数说明

参数

说明

defaults

NSDictionary的字典

fileName

包含本地配置的plist文件

字典的key必须最多可包含 256 个字符,且必须以下划线或英文字母(A-Z、a-z)开头,还可以包含数字

接口函数

/**
 *  @brief 设置本地默认配置
 *  @param defaults 对应的本地配置
 */
+ (void)setDefaults:(nullable NSDictionary<NSString *, NSObject *> *)defaults;

/**
 *  @brief 设置本地默认配置
 *  @param fileName 包含本地配置的plist文件
 */
+ (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName;

详细集成及示例代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    [UMRemoteConfig remoteConfigWithDelegate:self withConfigSettings:nil];

    [UMRemoteConfig setDefaultsFromPlistFileName:@"defaultsName"];
}

获取远程配置的值

介绍及参数说明

参数

说明

key

字典的key

接口函数

/**
 *  @brief 获取配置信息
 *  @param key 对应的key
 *  @note 获取配置的有限顺利,远程配置->Defaults
 */
+ (nullable id)configValueForKey:(nullable NSString *)key;

详细集成及示例代码

- (void)viewDidLoad {
    [super viewDidLoad];
    [UMRemoteConfig configValueForKey:@"home_color"];

}

激活远程配置

介绍及参数说明

参数

说明

completionHandler

激活回调

接口函数

/**
 *  @brief 激活本地配置
 *  @param completionHandler 回调
 */
+ (void)activateWithCompletionHandler:(nullable UMRemoteConfigActivateCompletion)completionHandler;

详细集成及示例代码

- (void)viewDidLoad {
    [super viewDidLoad];
    [UMRemoteConfig activateWithCompletionHandler:nil];  
}

高级功能

初始化配置类UMRemoteConfigSettings

介绍及属性说明

属性

说明

minimumFetchInterval

获取远程配置的时间间隔,默认30秒

fetchTimeout

获取远程配置的超时时间,默认60s

minimumFetchInterval

获取远程配置后,是否激活

详细集成及示例代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    UMRemoteConfigSettings*  settings = [UMRemoteConfigSettings new];
    [UMRemoteConfig remoteConfigWithDelegate:self withConfigSettings: settings];

    [UMRemoteConfig setDefaultsFromPlistFileName:@"defaultsName"];
}

通知代理协议UMRemoteConfigDelegate

拉取配置通知

介绍及参数说明

参数

说明

status

see UMRemoteConfigFetchStatus

error

错误信息

userInfo

该回调的扩展信息

协议接口
/**
 *  @brief 获取服务器的网络请求的回调
 *  @param status see UMRemoteConfigFetchStatus
 *  @param error 错误信息
 *  @param userInfo  该回调的扩展信息
 *  @note  调用函数触发此回调
 *         fetchWithCompletionHandler
 *         fetchAndActivateWithCompletionHandler
 */
-(void)remoteConfigFetched:(UMRemoteConfigFetchStatus)status
                           error:(nullable NSError*)error
                        userInfo:(nullable id)userInfo;

远程配置被激活的通知

介绍及参数说明

参数

说明

status

see UMRemoteConfigFetchStatus

error

错误信息

userInfo

该回调的扩展信息

协议接口
/**
 *  @brief 远程配置被激活的回调
 *  @param status see UMRemoteConfigActiveStatus
 *  @param error 错误信息
 *  @param userInfo  该回调的扩展信息
 *  @note  调用函数触发此回调
 *         fetchAndActivateWithCompletionHandler
 *         activateWithCompletionHandler
 */
-(void)remoteConfigActivated:(UMRemoteConfigActiveStatus)status
                       error:(nullable NSError*)error
                    userInfo:(nullable id)userInfo;

配置已经准备就绪的通知

介绍及参数说明

参数

说明

status

see UMRemoteConfigFetchStatus

error

错误信息

userInfo

该回调的扩展信息

协议接口
/**
 *  @brief 配置已经准备就绪
 *  @param status see UMRemoteConfigActiveStatus
 *  @param error 错误信息
 *  @param userInfo  该回调的扩展信息
 *  @note  调用函数触发此回调
 *         fetchWithCompletionHandler
 */
-(void)remoteConfigReady:(UMRemoteConfigActiveStatus)status
                   error:(nullable NSError*)error
                userInfo:(nullable id)userInfo;