Important: Since June 28, 2020, mPaaS has stopped support for the baseline 10.1.32. Please use 10.1.68 or 10.1.60 instead. For how to upgrade the baseline from version 10.1.32 to 10.1.68 or 10.1.60, see mPaaS 10.1.68 upgrade guide or mPaaS 10.1.60 upgrade guide. |
Switch configuration refers to the capability of dynamically modifying client-side code processing logic without releasing a new version on the client. The client controls relevant processing according to the extracted switch value that is dynamically configured at backend. By using the switch configuration service, you can configure, modify and push various types of switches. The switch refers to key/value
pair.
mPaaS provides the configuration management service ConfigService to realize switch configuration. By default, the syncing logic is syncing a switch value at the cold start of the application, or syncing a switch value if half an hour passed since last sync after the application returns to the foreground. In addition, ConfigService also provides an interface for immediate sync and the logic for monitoring configuration changes, by which configuration can be refreshed as soon as it is changed.
To realize switch configuration management, you need to add the corresponding iOS SDK, configure the project and read the configuration.
Prerequisites
The project is connected to mPaaS. For more information, refer to: Access based on native framework and using Cocoapods.
About this task
This document introduce how to integrate the switch configuration in details based on the switch configuration code sample.
Add an SDK
In the Podfile, define
mPaaS_pod "mPaaS_Config"
to add the dependencies of the switch configuration component.Based on requirements, run the
pod install
orpod update
command.
Configure a project
mPaaS encapsulates the switch configuration capability to a service. and you need to register this service in service manager before using it, as shown in the following figure.
Read the configurations
Values of switch keys can be dynamically released in the mPaaS console. On the left navigation pane, choose Mobile Delivery Service > Configuration management. Click Configuration Keys to view the detailed configurations.
What to do next
Obtain switch value
In the mPaaS Console, add necessary switch configuration items in Mobile Delivery Service > Configuration management, and deliver the configuration items by platform, whitelist, percentage, version, device model, iOS version and other information. For detailed operations, see Manage configurations.
When the switch key is released through the console, the client can get the key value corresponding to the switch key by calling relevant interface.
+ (void)testStringForKey
{
id<APConfigService>configService = [DTContextGet() findServiceByName:@"APConfigService"];
NSString *configValue = [configService stringValueForKey:@"BillEntrance"];
assert (configValue && [configValue isKindOfClass:[NSString class]]);
}
Advanced operations
Set the time when the client pulls a switch value:
During cold start of the application
30 minutes later than last pull after the application returns to the foreground
NoteThe interval of 30 minutes is the default value. You can modify the interval by adding switch
Load_Config_Interval
on the Configuration Switch Management page under Mobile Delivery Service in the mPaaS console. For more information about the steps, see Manage configurations.
Dynamically monitor switch value changes
You can add an observer for a specified key to dynamically monitor switch value changes.
When the client pulls switch configurations, you can obtain the latest switch value of the specified key in the callback method.
You can forcibly pull a switch value from the console by using an SDK.