A simple A/B testing framework for remotely switching features on and off and having the changes reflect in the app immediately.
Initialize the defaults with params, a dictionary containing base URLs for staging and production.
NSDictionary *params = @{kRFFeatureToggleBaseURLStringForStagingKey : @"https://staging/",
kRFFeatureToggleBaseURLStringForProductionKey : @"https://production/"};
[RFFeatureToggleDefaults sharedDefaultsWithMode:RFFeatureToggleModeProduction params:params];
For an easy start there are 3 convenience methods:
[RFeatureToggle isEnabled:@"feature"];
If the API supports features within features within features, these can be separated with dots like
[RFeatureToggle isEnabled:@"feature.subfeature.subsubfeature"];
[RFeatureToggle refresh];
This can be called on applicationDidBecomeActive:
or whenever convenient. After the initial call the features are automatically refreshed after 24 hours if app has been continuously running in foreground. A custom time interval can be set as default, for example [RFFeatureToggleDefaults sharedDefaults].refreshTimeInterval = 120.0f;
.
NSArray *features = [RFeatureToggle allFeatures];
Subscribe to RFFeatureToggleUpdatedNotification
to receive updates. The notification is triggered only when there has been a change in features.
To switch between staging and production use
[RFFeatureToggleDefaults switchToMode:RFFeatureToggleModeProduction]
Alternatively, to switch to custom URL that was not provided on initialization, there's a convenience method
[RFFeatureToggleDefaults switchToCustomModeWithBaseURLString:@"https://testURL"]
Calling [RFFeatureToggleDefaults sharedDefaults].mode)]
will return the mode it's operating in (production, staging, custom).
For fine tuning check the CocoaDocs.
To inspect the features, there are convenience methods in RFFeature
class:
- description, example output:
feature2: disabled
- recursiveDescription, example output:
feature2: disabled
|_feature3: disabled
|_feature5: disabled
|_feature6: enabled
|_feature4: enabled
RFFeatureTableViewController
lists all features that can be navigated through. It has a refresh control so features can be refreshed to ensure the latest changes are present. This is to be used for QA purposes.
This is demonstrated in the example project. To run the example project, run pod install
from the Example directory first.
Aside convenience methods provided in RFFeatureToggle
class, there are model-controller extensions of RFFeature
based on Data Mapper design pattern, as well as RFFeatureCache
class that handles persistence and auto update. Examples:
[RFFeature fetchFeaturesUsingBlock:^(BOOL succeeded, NSError *error) {
if (!succeeded)
{
//handle error
}
}];
NSTimeInterval secondsSinceLastSuccessfulUpdate = [RFFeatureCache timeIntervalSinceLastSuccessfulUpdate];
if (secondsSinceLastSuccessfulUpdate > 120.0f)
{
//do something
}
Logging can be configured by calling [RFFeatureToggle setLoggingLevel:];
using one of the predefined logging levels:
- RFFeatureToggleLogLevelOff: Don't log anything
- RFFeatureToggleLoggingLevelError: Log all errors
- RFFeatureToggleLoggingLevelWarn: Log warnings and errors
- RFFeatureToggleLoggingLevelInfo: Log informative, warning and error messages
- RFFeatureToggleLoggingLevelDebug: Log all debug, informative, warning and error messages
- RFFeatureToggleLoggingLevelVerbose: Log verbose diagnostic, informative, warning and error messages
If it's available, RFFeatureToggle will direct its logs to CocoaLumberjack. All you need to do is make sure you've imported CocoaLumberjack before you import RFFeatureToggle, like so:
#import <CocoaLumberjack/CocoaLumberjack.h>
#import <RFFeatureToggle/RFFeatureToggle.h>
- A server that returns a list of features in the specified format. See Fixtures for an example of the response.
- iOS9.3+
RFFeatureToggle is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "RFFeatureToggle"
For a complete documentation see CocoaDocs.
RFFeatureToggle is available under the MIT license. See the LICENSE file for more info.