Remote configuration for Cocoa apps
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
Add the below to your podfile.
Copiedsource 'https://github.com/CocoaPods/Specs.git'
target 'TARGET NAME' do
pod 'AppticsRemoteConfig'
end
Import
Copied#import <AppticsRemoteConfig/AppticsRemoteConfig.h>
Copiedimport AppticsRemoteConfig
- Add the parameters and conditions in the Remote Config UI, refer to the user guide.
Enable Remote Config
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.defaultConfig().enableRemoteConfig = true
Apptics.initialize(withVerbose: true)
return true
}
Fetch and activate configurations
- To fetch and activate configurations from the server, call the fetchAndActivate() method.
Copied[[APRemoteConfig shared] fetchAndActivate];
CopiedAPRemoteConfig.shared.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;
}
}];
Copiedlet remoteConfig = APRemoteConfig.shared
remoteConfig.fetchRemoteConfig { status in
if status == .success || status == .upToDate {
remoteConfig.activateFetched()
let primaryColor = remoteConfig["primaryColor"].stringValue
}
}
Listening for Remote config updates
Copied[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateRcValues:) name:@"APRemoteConfigUpdateNotification" object:nil];
- (void)updateRcValues:(NSNotification *)notification {
// Handle updated remote config values
}
CopiedNotificationCenter.default.addObserver(self, selector: #selector(updateRcValues), name: NSNotification.Name("APRemoteConfigUpdateNotification"), object: nil)
@objc func updateRcValues(notification: Notification) {
// Handle updated remote config values
}
Fetch string value with cold fetch and fallback
Copied[[APRemoteConfig shared] getStringValue:@"key" coldFetch:YES fallbackWithOfflineValue:YES];
CopiedAPRemoteConfig.shared.getStringValue("key", coldFetch: true, fallbackWithOfflineValue: true)
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.
Custom condition criteria
Use the below method to set the custom condition criteria.
Copied[APRemoteConfig.shared addCustomCriteria:@"criteriaKey" value:@"criteriaValue"];
CopiedAPRemoteConfig.shared.addCustomCriteria("criteriaKey", value: "criteriaValue")