Remote Configuration
Remote Config enables you to change the behavior or appearance of the app by making changes to the server side values. To add the parameters and conditions in the Remote Config UI, refer to the user guide.
Installation
Copiedsource 'https://github.com/CocoaPods/Specs.git'
target 'TARGET NAME' do
pod 'AppticsRemoteConfig'
end
Import
Copied#import <AppticsRemoteConfig/AppticsRemoteConfig.h>
Copied import AppticsRemoteConfig
- Add the parameters and conditions in the Remote Config UI, refer to the user guide.
- To enable Remote Config, call the enable of APRemoteConfig class in your app launch.
Copied- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
[AppticsConfig defaultConfig].enableRemoteConfig=true
[Apptics initializeWithVerbose:<#(BOOL)#>];
return true;
}
Copiedfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppticsConfig.default.enableRemoteConfig=true
Apptics.initialize(withVerbose: <#T##Bool#>)
return true
}
- To fetch and activate configurations from the server, call the fetchAndActivate() method.
Copied[[APRemoteConfig shared] fetchAndActivate]
Copied let remoteConfig = APRemoteConfig.shared()
remoteConfig.fetchAndActivate()
- Fetch config with completion handler.
CopiedAPRemoteConfig *remoteConfig = [APRemoteConfig shared];
[remoteConfig fetchRemoteConfigWithCompletion:^(APRemoteConfigFetchStatus status) {
if (status == APRemoteConfigFetchStatusSuccess || status == APRemoteConfigFetchStatusUpToDate){
[remoteConfig activateFetched];
NSString *primaryColor = remoteConfig[@"primaryColor"].stringValue;
}
}];
CopiedremoteConfig.fetch { (status) in
if (status == APRemoteConfigFetchStatus.statusSuccess || status == APRemoteConfigFetchStatus.UpToDate){
remoteConfig.activateFetched()
if let color = remoteConfig.configValue(forKey: "primaryColor").stringValue
}
}
- Example for listening APRemoteConfigUpdateNotification and update the values.
Copied [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateRcValues:) name:@"APRemoteConfigUpdateNotification" object:nil];
-(void) updateRcValues : (NSNotification*) notification{
//do stuff using the updated remote config values.
}
CopiedNotificationCenter.default.addObserver(
self,
selector: #selector(updateRcValues:),
name: "APRemoteConfigUpdateNotification",
object: nil)
private func updateRcValues(notification: NSNotification){
//do stuff using the updated remote config values.
}
- To get string value with coldfetch and fallback offline value.
Copied[[APRemoteConfig shared] getStringValue:<#(nonnull NSString *)#> coldFetch:<#(BOOL)#> fallbackWithOfflineValue:<#(BOOL)#>]
CopiedAPRemoteConfig.shared().getStringValue(<#T##key: String##String#>, coldFetch: <#T##Bool#>, fallbackWithOfflineValue: <#T##Bool#>)
By, default values will not be fetched from the network to every fetch call; the fetchValue/fetchValues method will return cached values, if the values were recently fetched from the network. The coldFetch parameter can be enabled if you need fetch value methods to always fetch and return the current value from the network.
Enable the coldFetch parameter with caution, since only three fetch calls are allowed per minute. Any further calls will return null/default values.